ecrs-auth-core 1.0.85 → 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.
@@ -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
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecrs-auth-core",
3
- "version": "1.0.85",
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",