@ciscode/authentication-kit 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -188,14 +188,22 @@ Content-Type: application/json
188
188
  "fname": "Test",
189
189
  "lname": "User"
190
190
  },
191
- "username": "Userrr",
191
+ "username": "custom-username",
192
192
  "email": "user@example.com",
193
193
  "password": "Pa$$word!",
194
194
  "phoneNumber": "+1234567890",
195
- "avatar": "https://example.com/avatar.jpg"
195
+ "avatar": "https://example.com/avatar.jpg",
196
+ "jobTitle": "Software Engineer",
197
+ "company": "Ciscode"
196
198
  }
197
199
  ```
198
200
 
201
+ **Notes:**
202
+
203
+ - `username` is now **optional**. If not provided, it will be auto-generated as `fname-lname` (e.g., `test-user`)
204
+ - `jobTitle` and `company` are **optional** profile fields
205
+ - All other fields work as before
206
+
199
207
  **Response:**
200
208
 
201
209
  ```json
@@ -387,10 +395,12 @@ All permissions are assigned to the `admin` role.
387
395
  fname: string,
388
396
  lname: string
389
397
  },
390
- username: string (unique, 3-30 chars),
398
+ username: string (unique, 3-30 chars, auto-generated as fname-lname if not provided),
391
399
  email: string (unique, validated),
392
400
  phoneNumber?: string (unique, 10-14 digits),
393
401
  avatar?: string (default: 'default.jpg'),
402
+ jobTitle?: string,
403
+ company?: string,
394
404
  password: string (hashed, min 6 chars),
395
405
  roles: ObjectId[] (references Role),
396
406
  isVerified: boolean (default: false),
@@ -4,10 +4,12 @@ declare class FullNameDto {
4
4
  }
5
5
  export declare class RegisterDto {
6
6
  fullname: FullNameDto;
7
- username: string;
7
+ username?: string;
8
8
  email: string;
9
9
  password: string;
10
10
  phoneNumber?: string;
11
11
  avatar?: string;
12
+ jobTitle?: string;
13
+ company?: string;
12
14
  }
13
15
  export {};
@@ -31,6 +31,7 @@ __decorate([
31
31
  __metadata("design:type", FullNameDto)
32
32
  ], RegisterDto.prototype, "fullname", void 0);
33
33
  __decorate([
34
+ (0, class_validator_1.IsOptional)(),
34
35
  (0, class_validator_1.IsString)(),
35
36
  (0, class_validator_1.MinLength)(3),
36
37
  __metadata("design:type", String)
@@ -54,3 +55,13 @@ __decorate([
54
55
  (0, class_validator_1.IsString)(),
55
56
  __metadata("design:type", String)
56
57
  ], RegisterDto.prototype, "avatar", void 0);
58
+ __decorate([
59
+ (0, class_validator_1.IsOptional)(),
60
+ (0, class_validator_1.IsString)(),
61
+ __metadata("design:type", String)
62
+ ], RegisterDto.prototype, "jobTitle", void 0);
63
+ __decorate([
64
+ (0, class_validator_1.IsOptional)(),
65
+ (0, class_validator_1.IsString)(),
66
+ __metadata("design:type", String)
67
+ ], RegisterDto.prototype, "company", void 0);
@@ -15,6 +15,8 @@ export declare class User {
15
15
  roles: Types.ObjectId[];
16
16
  isVerified: boolean;
17
17
  isBanned: boolean;
18
+ jobTitle?: string;
19
+ company?: string;
18
20
  }
19
21
  export declare const UserSchema: import("mongoose").Schema<User, import("mongoose").Model<User, any, any, any, Document<unknown, any, User> & User & {
20
22
  _id: Types.ObjectId;
@@ -80,6 +80,14 @@ __decorate([
80
80
  (0, mongoose_1.Prop)({ default: false }),
81
81
  __metadata("design:type", Boolean)
82
82
  ], User.prototype, "isBanned", void 0);
83
+ __decorate([
84
+ (0, mongoose_1.Prop)({ trim: true, sparse: true }),
85
+ __metadata("design:type", String)
86
+ ], User.prototype, "jobTitle", void 0);
87
+ __decorate([
88
+ (0, mongoose_1.Prop)({ trim: true, sparse: true }),
89
+ __metadata("design:type", String)
90
+ ], User.prototype, "company", void 0);
83
91
  exports.User = User = __decorate([
84
92
  (0, mongoose_1.Schema)({ timestamps: true })
85
93
  ], User);
@@ -52,6 +52,7 @@ const jwt = __importStar(require("jsonwebtoken"));
52
52
  const user_repository_1 = require("../repositories/user.repository");
53
53
  const mail_service_1 = require("./mail.service");
54
54
  const role_repository_1 = require("../repositories/role.repository");
55
+ const helper_1 = require("../utils/helper");
55
56
  let AuthService = class AuthService {
56
57
  constructor(users, mail, roles) {
57
58
  this.users = users;
@@ -100,6 +101,10 @@ let AuthService = class AuthService {
100
101
  return { accessToken, refreshToken };
101
102
  }
102
103
  async register(dto) {
104
+ // Generate username from fname-lname if not provided
105
+ if (!dto.username || dto.username.trim() === '') {
106
+ dto.username = (0, helper_1.generateUsernameFromName)(dto.fullname.fname, dto.fullname.lname);
107
+ }
103
108
  if (await this.users.findByEmail(dto.email))
104
109
  throw new Error('Email already in use.');
105
110
  if (await this.users.findByUsername(dto.username))
@@ -118,6 +123,8 @@ let AuthService = class AuthService {
118
123
  email: dto.email,
119
124
  phoneNumber: dto.phoneNumber,
120
125
  avatar: dto.avatar,
126
+ jobTitle: dto.jobTitle,
127
+ company: dto.company,
121
128
  password: hashed,
122
129
  roles: [userRole._id],
123
130
  isVerified: false,
@@ -18,12 +18,17 @@ const bcryptjs_1 = __importDefault(require("bcryptjs"));
18
18
  const user_repository_1 = require("../repositories/user.repository");
19
19
  const role_repository_1 = require("../repositories/role.repository");
20
20
  const mongoose_1 = require("mongoose");
21
+ const helper_1 = require("../utils/helper");
21
22
  let UsersService = class UsersService {
22
23
  constructor(users, rolesRepo) {
23
24
  this.users = users;
24
25
  this.rolesRepo = rolesRepo;
25
26
  }
26
27
  async create(dto) {
28
+ // Generate username from fname-lname if not provided
29
+ if (!dto.username || dto.username.trim() === '') {
30
+ dto.username = (0, helper_1.generateUsernameFromName)(dto.fullname.fname, dto.fullname.lname);
31
+ }
27
32
  if (await this.users.findByEmail(dto.email))
28
33
  throw new Error('Email already in use.');
29
34
  if (await this.users.findByUsername(dto.username))
@@ -39,6 +44,8 @@ let UsersService = class UsersService {
39
44
  email: dto.email,
40
45
  phoneNumber: dto.phoneNumber,
41
46
  avatar: dto.avatar,
47
+ jobTitle: dto.jobTitle,
48
+ company: dto.company,
42
49
  password: hashed,
43
50
  roles: [],
44
51
  isVerified: true,
@@ -1 +1,2 @@
1
1
  export declare function getMillisecondsFromExpiry(expiry: string | number): number;
2
+ export declare function generateUsernameFromName(fname: string, lname: string): string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getMillisecondsFromExpiry = getMillisecondsFromExpiry;
4
+ exports.generateUsernameFromName = generateUsernameFromName;
4
5
  function getMillisecondsFromExpiry(expiry) {
5
6
  if (typeof expiry === 'number') {
6
7
  return expiry * 1000;
@@ -20,3 +21,6 @@ function getMillisecondsFromExpiry(expiry) {
20
21
  return 0;
21
22
  }
22
23
  }
24
+ function generateUsernameFromName(fname, lname) {
25
+ return `${fname.toLowerCase()}-${lname.toLowerCase()}`;
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciscode/authentication-kit",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "NestJS auth kit with local + OAuth, JWT, RBAC, password reset.",
5
5
  "publishConfig": {
6
6
  "access": "public"