ecrs-auth-core 1.0.79 → 1.0.81

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.
@@ -27,12 +27,23 @@ export declare class AuthController {
27
27
  departmentId: any;
28
28
  designationId: any;
29
29
  lastLoginTime: any;
30
- is_otp_verified: number | boolean;
30
+ is_reset_password: number;
31
31
  profile_photo_url: string;
32
32
  };
33
33
  };
34
34
  access_token: string;
35
35
  }>;
36
+ logout(request: any): Promise<{
37
+ status: boolean;
38
+ message: string;
39
+ data: {
40
+ user: {
41
+ id: any;
42
+ email: any;
43
+ logoutTime: string;
44
+ };
45
+ };
46
+ }>;
36
47
  /**
37
48
  * Extract additional client data from request and user-agent
38
49
  */
@@ -72,6 +72,41 @@ let AuthController = class AuthController {
72
72
  }); // Log errors for debugging
73
73
  return loginResponse;
74
74
  }
75
+ async logout(request) {
76
+ // Get user from JWT token (assuming JwtAuthGuard is applied)
77
+ const user = request.user;
78
+ if (!user || !user.id) {
79
+ throw new common_1.UnauthorizedException('User not authenticated');
80
+ }
81
+ console.log(`🚪 Logout request for user ${user.id} (${user.email})`);
82
+ try {
83
+ // Update logout details in both tables
84
+ await Promise.all([
85
+ this.authService.updateLastLoginLogout(user.id).catch((err) => {
86
+ console.error('❌ Error updating logout in tbl_user_last_login:', err.message);
87
+ }),
88
+ this.authService.updateLoginLogoutDetailsJson(user.id).catch((err) => {
89
+ console.error('❌ Error updating logout in tbl_user_login_details:', err.message);
90
+ })
91
+ ]);
92
+ console.log(`✅ User ${user.id} logged out successfully`);
93
+ return {
94
+ status: true,
95
+ message: 'Logout successful',
96
+ data: {
97
+ user: {
98
+ id: user.id,
99
+ email: user.email,
100
+ logoutTime: new Date().toISOString()
101
+ }
102
+ }
103
+ };
104
+ }
105
+ catch (error) {
106
+ console.error('❌ Error during logout:', error?.message || error);
107
+ throw new common_1.UnauthorizedException('Logout failed');
108
+ }
109
+ }
75
110
  /**
76
111
  * Extract additional client data from request and user-agent
77
112
  */
@@ -139,7 +174,6 @@ let AuthController = class AuthController {
139
174
  getClientIp(request) {
140
175
  let ip = '';
141
176
  // Check X-Forwarded-For header (most common with proxies)
142
- console.log('Headers:', request.headers);
143
177
  const xForwardedFor = request.headers['x-forwarded-for'];
144
178
  if (xForwardedFor) {
145
179
  const ips = Array.isArray(xForwardedFor)
@@ -221,6 +255,26 @@ __decorate([
221
255
  __metadata("design:paramtypes", [Object, login_dto_1.LoginDto]),
222
256
  __metadata("design:returntype", Promise)
223
257
  ], AuthController.prototype, "login", null);
258
+ __decorate([
259
+ (0, common_1.Post)('logout'),
260
+ (0, common_1.HttpCode)(200),
261
+ (0, swagger_1.ApiOperation)({
262
+ summary: 'User logout',
263
+ description: 'Logout user and update session end time'
264
+ }),
265
+ (0, swagger_1.ApiOkResponse)({
266
+ description: 'Logout successful',
267
+ example: {
268
+ status: true,
269
+ message: 'Logout successful'
270
+ }
271
+ }),
272
+ (0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }),
273
+ __param(0, (0, common_1.Req)()),
274
+ __metadata("design:type", Function),
275
+ __metadata("design:paramtypes", [Object]),
276
+ __metadata("design:returntype", Promise)
277
+ ], AuthController.prototype, "logout", null);
224
278
  exports.AuthController = AuthController = __decorate([
225
279
  (0, swagger_1.ApiTags)('auth'),
226
280
  (0, swagger_1.ApiBearerAuth)(),
@@ -107,7 +107,7 @@ export declare class AuthService {
107
107
  departmentId: any;
108
108
  designationId: any;
109
109
  lastLoginTime: any;
110
- is_otp_verified: number | boolean;
110
+ is_reset_password: number;
111
111
  profile_photo_url: string;
112
112
  };
113
113
  };
@@ -54,7 +54,7 @@ let AuthService = class AuthService {
54
54
  constructor(jwtService, options) {
55
55
  this.jwtService = jwtService;
56
56
  this.options = options;
57
- this.uploadPhotoDir = './uploads/organization/photos';
57
+ this.uploadPhotoDir = 'uploads/organization/photos';
58
58
  const { repositories } = options;
59
59
  this.userRepo = repositories.userRepo;
60
60
  this.roleRepo = repositories.roleRepo;
@@ -433,6 +433,13 @@ let AuthService = class AuthService {
433
433
  // Continue with null values if fetch fails
434
434
  }
435
435
  }
436
+ let is_reset_password = 0;
437
+ if (user.isOtpVerified === 0 || user.isOtpVerified == 0) {
438
+ is_reset_password = 1;
439
+ }
440
+ else {
441
+ is_reset_password = 0;
442
+ }
436
443
  const payload = {
437
444
  id: user.id,
438
445
  email: user.email,
@@ -453,7 +460,7 @@ let AuthService = class AuthService {
453
460
  departmentId,
454
461
  designationId,
455
462
  lastLoginTime: lastLoginTime,
456
- is_otp_verified: user.isOtpVerified || false,
463
+ is_reset_password: is_reset_password,
457
464
  };
458
465
  return {
459
466
  status: true,
@@ -478,8 +485,8 @@ let AuthService = class AuthService {
478
485
  departmentId,
479
486
  designationId,
480
487
  lastLoginTime: lastLoginTime,
481
- is_otp_verified: user.isOtpVerified || false,
482
- profile_photo_url: `${this.uploadPhotoDir}`,
488
+ is_reset_password: is_reset_password,
489
+ profile_photo_url: `${this.uploadPhotoDir}/${user.userImage}`,
483
490
  },
484
491
  },
485
492
  access_token: this.jwtService.sign(payload),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecrs-auth-core",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "description": "Centralized authentication and authorization module for ECRS apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",