ecrs-auth-core 1.0.102 → 1.0.103

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.
@@ -32,7 +32,7 @@ let AuthController = class AuthController {
32
32
  const additionalData = this.extractClientData(request, userAgent);
33
33
  console.log(`📍 Login attempt from IP: ${clientIp}, User-Agent: ${userAgent}`);
34
34
  // Validate user with IP restriction check
35
- const user = await this.authService.validateUser(body.email, body.password, clientIp);
35
+ const user = await this.authService.validateUser(body.email, body.password, clientIp, Number(body.moduleId));
36
36
  if (!user) {
37
37
  // Save failed login attempt to both tables
38
38
  await this.authService.saveLastLogin({ email: body.email }, clientIp, 'failed', 'Invalid credentials or IP not allowed', additionalData).catch((err) => {
@@ -25,7 +25,7 @@ export declare class AuthService {
25
25
  private readonly employeeWorkProfileRepo;
26
26
  private uploadPhotoDir;
27
27
  constructor(jwtService: JwtService, options: AuthCoreOptions);
28
- validateUser(email: string, password: string, clientIp?: string): Promise<User>;
28
+ validateUser(email: string, password: string, clientIp?: string, moduleId?: number): Promise<User>;
29
29
  /**
30
30
  * Validate IP restriction for a user
31
31
  *
@@ -49,6 +49,7 @@ exports.AuthService = void 0;
49
49
  const common_1 = require("@nestjs/common");
50
50
  const jwt_1 = require("@nestjs/jwt");
51
51
  const bcrypt = __importStar(require("bcrypt"));
52
+ const typeorm_1 = require("typeorm");
52
53
  const constants_1 = require("./constants/constants");
53
54
  let AuthService = class AuthService {
54
55
  constructor(jwtService, options) {
@@ -70,8 +71,25 @@ let AuthService = class AuthService {
70
71
  this.loginDetailsRepo = repositories.loginDetailsRepo || null;
71
72
  this.employeeWorkProfileRepo = repositories.employeeWorkProfileRepo || null;
72
73
  }
73
- async validateUser(email, password, clientIp) {
74
- const user = await this.userRepo.findOne({ where: { email } });
74
+ async validateUser(email, password, clientIp, moduleId) {
75
+ const whereClause = { email, deletedBy: null, deletedAt: null };
76
+ //role-id
77
+ //1-"Superadmin" 2-"Admin" 3-"Employee" 5-"CUSTOMER_BOOKER" 6-"SECURITY" 7-"SUPPLIER"
78
+ //module-id
79
+ // 1 "HR" , 2 "ETS" ,3 "Spot",4 "Account",5 "Superadmin",6 "Vendor",7 "Customer"
80
+ const modulearray = [1, 2, 3, 4, 5];
81
+ if (moduleId === 7) {
82
+ // Customer module: allow CUSTOMER_BOOKER(5), SECURITY(6), SUPPLIER(7)
83
+ whereClause.roleId = (0, typeorm_1.In)([5, 1, 2]);
84
+ }
85
+ else if (moduleId === 6) {
86
+ // vendor module: allow CUSTOMER_BOOKER(5), SECURITY(6), SUPPLIER(7)
87
+ whereClause.roleId = (0, typeorm_1.In)([7, 1, 2]);
88
+ }
89
+ else if (moduleId !== undefined && modulearray.includes(moduleId)) {
90
+ whereClause.roleId = (0, typeorm_1.In)([1, 2, 3]);
91
+ }
92
+ const user = await this.userRepo.findOne({ where: whereClause });
75
93
  if (!user) {
76
94
  throw new common_1.UnauthorizedException('Invalid email');
77
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecrs-auth-core",
3
- "version": "1.0.102",
3
+ "version": "1.0.103",
4
4
  "description": "Centralized authentication and authorization module for ECRS apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",