@ciscode/authentication-kit 1.4.0 → 1.4.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
@@ -107,17 +107,18 @@ export class AppModule implements OnModuleInit {
107
107
 
108
108
  ## API Routes
109
109
 
110
- ### Local Auth Routes (Public)
110
+ ### Local Auth Routes
111
111
 
112
112
  ```
113
- POST /api/auth/register
114
- POST /api/auth/verify-email
115
- POST /api/auth/resend-verification
116
- POST /api/auth/login
117
- POST /api/auth/refresh-token
118
- POST /api/auth/forgot-password
119
- POST /api/auth/reset-password
120
- DELETE /api/auth/account (protected)
113
+ POST /api/auth/register | Register new user (public)
114
+ POST /api/auth/verify-email | Verify email with token (public)
115
+ POST /api/auth/resend-verification | Resend verification email (public)
116
+ POST /api/auth/login | Login with credentials (public)
117
+ POST /api/auth/refresh-token | Refresh access token (public)
118
+ POST /api/auth/forgot-password | Request password reset (public)
119
+ POST /api/auth/reset-password | Reset password with token (public)
120
+ GET /api/auth/me | Get current user profile (protected)
121
+ DELETE /api/auth/account | Delete own account (protected)
121
122
  ```
122
123
 
123
124
  ### OAuth Routes - Mobile Exchange (Public)
@@ -321,6 +322,54 @@ Content-Type: application/json
321
322
  }
322
323
  ```
323
324
 
325
+ ### Get Current User Profile
326
+
327
+ **Request:**
328
+
329
+ ```json
330
+ GET /api/auth/me
331
+ Authorization: Bearer access-token
332
+ ```
333
+
334
+ **Response:**
335
+
336
+ ```json
337
+ {
338
+ "ok": true,
339
+ "data": {
340
+ "_id": "507f1f77bcf86cd799439011",
341
+ "fullname": {
342
+ "fname": "Test",
343
+ "lname": "User"
344
+ },
345
+ "username": "test-user",
346
+ "email": "user@example.com",
347
+ "avatar": "https://example.com/avatar.jpg",
348
+ "phoneNumber": "+1234567890",
349
+ "jobTitle": "Software Engineer",
350
+ "company": "Ciscode",
351
+ "isVerified": true,
352
+ "isBanned": false,
353
+ "roles": [
354
+ {
355
+ "_id": "507f1f77bcf86cd799439012",
356
+ "name": "user",
357
+ "permissions": [
358
+ {
359
+ "_id": "507f1f77bcf86cd799439013",
360
+ "name": "read:profile"
361
+ }
362
+ ]
363
+ }
364
+ ],
365
+ "createdAt": "2026-01-28T10:00:00.000Z",
366
+ "updatedAt": "2026-01-28T10:00:00.000Z"
367
+ }
368
+ }
369
+ ```
370
+
371
+ **Note:** Sensitive fields like `password` and `passwordChangedAt` are automatically excluded from the response.
372
+
324
373
  ### Delete Account
325
374
 
326
375
  **Request:**
@@ -19,6 +19,7 @@ export declare class AuthController {
19
19
  refresh(dto: RefreshTokenDto, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
20
20
  forgotPassword(dto: ForgotPasswordDto, res: Response): Promise<Response<any, Record<string, any>>>;
21
21
  resetPassword(dto: ResetPasswordDto, res: Response): Promise<Response<any, Record<string, any>>>;
22
+ getMe(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
22
23
  deleteAccount(req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
23
24
  microsoftExchange(body: {
24
25
  idToken: string;
@@ -84,6 +84,14 @@ let AuthController = class AuthController {
84
84
  const result = await this.auth.resetPassword(dto.token, dto.newPassword);
85
85
  return res.status(200).json(result);
86
86
  }
87
+ async getMe(req, res) {
88
+ var _a;
89
+ const userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a.sub;
90
+ if (!userId)
91
+ return res.status(401).json({ message: 'Unauthorized.' });
92
+ const result = await this.auth.getMe(userId);
93
+ return res.status(200).json(result);
94
+ }
87
95
  async deleteAccount(req, res) {
88
96
  var _a;
89
97
  const userId = (_a = req.user) === null || _a === void 0 ? void 0 : _a.sub;
@@ -202,6 +210,15 @@ __decorate([
202
210
  __metadata("design:paramtypes", [reset_password_dto_1.ResetPasswordDto, Object]),
203
211
  __metadata("design:returntype", Promise)
204
212
  ], AuthController.prototype, "resetPassword", null);
213
+ __decorate([
214
+ (0, common_1.Get)('me'),
215
+ (0, common_1.UseGuards)(authenticate_guard_1.AuthenticateGuard),
216
+ __param(0, (0, common_1.Req)()),
217
+ __param(1, (0, common_1.Res)()),
218
+ __metadata("design:type", Function),
219
+ __metadata("design:paramtypes", [Object, Object]),
220
+ __metadata("design:returntype", Promise)
221
+ ], AuthController.prototype, "getMe", null);
205
222
  __decorate([
206
223
  (0, common_1.Delete)('account'),
207
224
  (0, common_1.UseGuards)(authenticate_guard_1.AuthenticateGuard),
@@ -21,6 +21,10 @@ export declare class AuthService {
21
21
  accessToken: string;
22
22
  refreshToken: string;
23
23
  }>;
24
+ getMe(userId: string): Promise<{
25
+ ok: boolean;
26
+ data: any;
27
+ }>;
24
28
  register(dto: RegisterDto): Promise<{
25
29
  id: any;
26
30
  email: string;
@@ -113,6 +113,31 @@ let AuthService = class AuthService {
113
113
  const refreshToken = this.signRefreshToken({ sub: userId, purpose: 'refresh' });
114
114
  return { accessToken, refreshToken };
115
115
  }
116
+ async getMe(userId) {
117
+ try {
118
+ const user = await this.users.findByIdWithRolesAndPermissions(userId);
119
+ if (!user) {
120
+ throw new common_1.NotFoundException('User not found');
121
+ }
122
+ if (user.isBanned) {
123
+ throw new common_1.ForbiddenException('Account has been banned. Please contact support');
124
+ }
125
+ // Return user data without sensitive information
126
+ const userObject = user.toObject ? user.toObject() : user;
127
+ const { password, passwordChangedAt, ...safeUser } = userObject;
128
+ return {
129
+ ok: true,
130
+ data: safeUser
131
+ };
132
+ }
133
+ catch (error) {
134
+ if (error instanceof common_1.NotFoundException || error instanceof common_1.ForbiddenException) {
135
+ throw error;
136
+ }
137
+ this.logger.error(`Get profile failed: ${error.message}`, error.stack, 'AuthService');
138
+ throw new common_1.InternalServerErrorException('Failed to retrieve profile');
139
+ }
140
+ }
116
141
  async register(dto) {
117
142
  try {
118
143
  // Generate username from fname-lname if not provided
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciscode/authentication-kit",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "NestJS auth kit with local + OAuth, JWT, RBAC, password reset.",
5
5
  "publishConfig": {
6
6
  "access": "public"