ecrs-auth-core 1.0.84 → 1.0.87

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.
@@ -30,6 +30,8 @@ export declare class AuthController {
30
30
  designationId: any;
31
31
  lastLoginTime: any;
32
32
  is_reset_password: number;
33
+ profile_photo_url: string;
34
+ permissionTree: string[];
33
35
  };
34
36
  };
35
37
  access_token: string;
@@ -35,6 +35,7 @@ let AuthController = class AuthController {
35
35
  const user = await this.authService.validateUser(body.email, body.password, clientIp);
36
36
  console.log(`🔐 User validation result for ${body.email}: ${user ? 'Success' : 'Failed'}`);
37
37
  if (!user) {
38
+ console.warn(`⚠️ Failed login attempt for ${body.email} from IP ${clientIp}`);
38
39
  // Save failed login attempt to both tables
39
40
  await this.authService.saveLastLogin({ email: body.email }, clientIp, 'failed', 'Invalid credentials or IP not allowed', additionalData).catch((err) => {
40
41
  console.error('❌ Error saving failed login to tbl_user_last_login:', err.message);
@@ -44,6 +45,10 @@ let AuthController = class AuthController {
44
45
  }); // Log errors for debugging
45
46
  throw new common_1.UnauthorizedException('Login failed: email or password not matched or IP not allowed');
46
47
  }
48
+ else {
49
+ console.log(`✅ User ${body.email} authenticated successfully`);
50
+ }
51
+ console.log('📊 User details:', user);
47
52
  const requestedModuleId = Number(body.moduleId);
48
53
  if (!Number.isFinite(requestedModuleId)) {
49
54
  throw new common_1.UnauthorizedException('You are not authorized to access this module');
@@ -52,10 +57,11 @@ let AuthController = class AuthController {
52
57
  if (!allowedDb) {
53
58
  throw new common_1.UnauthorizedException('You are not authorized to access this module');
54
59
  }
55
- const perms = await this.authService.getPermissions(user.id);
56
- if (!Array.isArray(perms.modules) || !perms.modules.includes(requestedModuleId)) {
57
- throw new common_1.UnauthorizedException('You are not authorized to access this module');
58
- }
60
+ // const perms = await this.authService.getPermissions(user.id);
61
+ // console.log(`📊 User permissions for ${body.email}:`, perms);
62
+ // if (!Array.isArray(perms.modules) || !perms.modules.includes(requestedModuleId)) {
63
+ // throw new UnauthorizedException('You are not authorized to access this module');
64
+ // }
59
65
  const loginResponse = await this.authService.login(user, requestedModuleId);
60
66
  console.log(`✅ User ${body.email} logged in successfully to module ${requestedModuleId}`);
61
67
  // Save successful login details with additional client data to both tables
@@ -108,6 +108,8 @@ export declare class AuthService {
108
108
  designationId: any;
109
109
  lastLoginTime: any;
110
110
  is_reset_password: number;
111
+ profile_photo_url: string;
112
+ permissionTree: string[];
111
113
  };
112
114
  };
113
115
  access_token: string;
@@ -169,6 +169,7 @@ let AuthService = class AuthService {
169
169
  return !!access;
170
170
  }
171
171
  async getPermissions(userId) {
172
+ console.log(`🔍 Loading permissions for user ID ${userId}...`);
172
173
  return this.loadPermissions(userId);
173
174
  }
174
175
  /**
@@ -414,7 +415,9 @@ let AuthService = class AuthService {
414
415
  }
415
416
  }
416
417
  async login(user, selectedModuleId) {
418
+ console.log(`🔐 Logging in user ID ${user.id} with selected module ID ${selectedModuleId}...`);
417
419
  const permissionTree = await this.loadModulePermissions(user.id, selectedModuleId);
420
+ console.log(`📊 Loaded permissions for user ID ${user.id}:`, permissionTree);
418
421
  const role = await this.roleRepo.findOne({ where: { id: user.roleId } });
419
422
  const roleName = role?.roleName || null;
420
423
  const effectiveModuleId = Number.isFinite(selectedModuleId) ? selectedModuleId : user.moduleId ?? null;
@@ -478,7 +481,7 @@ let AuthService = class AuthService {
478
481
  mobileNo: user.mobileNo,
479
482
  userImage: user.userImage,
480
483
  employeeId: user.referenceId,
481
- permissions: permissionTree,
484
+ // permissions: permissionTree,
482
485
  parentId: user.parentId,
483
486
  referenceId: user.referenceId,
484
487
  branchId,
@@ -512,7 +515,8 @@ let AuthService = class AuthService {
512
515
  designationId,
513
516
  lastLoginTime: lastLoginTime,
514
517
  is_reset_password: is_reset_password,
515
- // profile_photo_url: `${this.uploadPhotoDir}/${user.userImage}`,
518
+ profile_photo_url: `${this.uploadPhotoDir}/${user.userImage}`,
519
+ permissionTree: permissionTree,
516
520
  },
517
521
  },
518
522
  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.84",
3
+ "version": "1.0.87",
4
4
  "description": "Centralized authentication and authorization module for ECRS apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",