ecrs-auth-core 1.0.82 → 1.0.83

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.
@@ -72,18 +72,24 @@ let AuthService = class AuthService {
72
72
  }
73
73
  async validateUser(email, password, clientIp) {
74
74
  const user = await this.userRepo.findOne({ where: { email } });
75
- if (!user)
76
- return null;
75
+ if (!user) {
76
+ throw new common_1.UnauthorizedException('The email address is invalid or not registered.');
77
+ }
77
78
  const isValid = await bcrypt.compare(password, user.password);
78
- if (!isValid)
79
- return null;
79
+ if (!isValid) {
80
+ throw new common_1.UnauthorizedException('The password is incorrect. Please try again.');
81
+ }
82
+ ;
83
+ if (user.status !== 1) {
84
+ throw new common_1.UnauthorizedException('Your account is inactive. Please contact support.');
85
+ }
80
86
  // console.log(this.ipRestrictionsRepo);
81
87
  // Check IP restrictions if provided and repository is available
82
88
  if (clientIp && this.ipRestrictionsRepo) {
83
89
  const ipAllowed = await this.validateIpRestriction(user.id, clientIp);
84
90
  if (!ipAllowed) {
85
- // IP restriction exists but doesn't match - return null to block login
86
- return null;
91
+ // IP restriction exists but doesn't match - throw UnauthorizedException to block login
92
+ throw new common_1.UnauthorizedException('Login denied: Your IP address is not allowed.');
87
93
  }
88
94
  }
89
95
  return user;
@@ -220,7 +226,14 @@ let AuthService = class AuthService {
220
226
  console.log(`📝 Last login details saved for user ${user.id} (${loginStatus})`);
221
227
  }
222
228
  catch (error) {
223
- console.error('Error saving last login details:', error);
229
+ if (error?.message?.includes('No metadata')) {
230
+ console.error('❌ ERROR: UserLastLoginEntity is not registered in your TypeORM configuration.\n' +
231
+ 'Please see ENTITY_SETUP_GUIDE.md for setup instructions.\n' +
232
+ 'Entity must be added to TypeOrmModule.forRoot(entities: [...]) in your app.');
233
+ }
234
+ else {
235
+ console.error('Error saving last login details:', error);
236
+ }
224
237
  // Don't throw error - this shouldn't block login
225
238
  }
226
239
  }
@@ -307,7 +320,14 @@ let AuthService = class AuthService {
307
320
  }
308
321
  }
309
322
  catch (error) {
310
- console.error('Error saving login details JSON:', error);
323
+ if (error?.message?.includes('No metadata')) {
324
+ console.error('❌ ERROR: LoginDetailsEntity is not registered in your TypeORM configuration.\n' +
325
+ 'Please see ENTITY_SETUP_GUIDE.md for setup instructions.\n' +
326
+ 'Entity must be added to TypeOrmModule.forRoot(entities: [...]) in your app.');
327
+ }
328
+ else {
329
+ console.error('Error saving login details JSON:', error);
330
+ }
311
331
  // Don't throw error - this shouldn't block login
312
332
  }
313
333
  }
@@ -356,7 +376,13 @@ let AuthService = class AuthService {
356
376
  console.log(`🚪 Logout details updated for user ${userId} on ${today.toDateString()}`);
357
377
  }
358
378
  catch (error) {
359
- console.error('Error updating logout details:', error);
379
+ if (error?.message?.includes('No metadata')) {
380
+ console.error('❌ ERROR: LoginDetailsEntity is not registered in your TypeORM configuration.\n' +
381
+ 'Please see ENTITY_SETUP_GUIDE.md for setup instructions.');
382
+ }
383
+ else {
384
+ console.error('Error updating logout details:', error);
385
+ }
360
386
  // Don't throw error - this shouldn't block logout
361
387
  }
362
388
  }
@@ -383,7 +409,13 @@ let AuthService = class AuthService {
383
409
  console.log(`🚪 Last login logout time updated for user ${userId}`);
384
410
  }
385
411
  catch (error) {
386
- console.error('Error updating last login logout time:', error);
412
+ if (error?.message?.includes('No metadata')) {
413
+ console.error('❌ ERROR: UserLastLoginEntity is not registered in your TypeORM configuration.\n' +
414
+ 'Please see ENTITY_SETUP_GUIDE.md for setup instructions.');
415
+ }
416
+ else {
417
+ console.error('Error updating last login logout time:', error);
418
+ }
387
419
  // Don't throw error - this shouldn't block logout
388
420
  }
389
421
  }
@@ -462,6 +494,10 @@ let AuthService = class AuthService {
462
494
  lastLoginTime: lastLoginTime,
463
495
  is_reset_password: is_reset_password,
464
496
  };
497
+ // Generate JWT token
498
+ const accessToken = this.jwtService.sign(payload);
499
+ // Update user's apiToken in the database
500
+ await this.userRepo.update({ id: user.id }, { apiToken: accessToken });
465
501
  return {
466
502
  status: true,
467
503
  message: 'Login successful',
@@ -489,7 +525,7 @@ let AuthService = class AuthService {
489
525
  profile_photo_url: `${this.uploadPhotoDir}/${user.userImage}`,
490
526
  },
491
527
  },
492
- access_token: this.jwtService.sign(payload),
528
+ access_token: accessToken,
493
529
  };
494
530
  }
495
531
  /**
@@ -34,6 +34,10 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
34
34
  console.log(`✅ User ${user.id} has access to module ${payload.moduleId}`);
35
35
  }
36
36
  console.log(`✅ JWT validated for user ${user.id}`);
37
+ if (user.status !== 1) {
38
+ console.log(`❌ User ${user.id} is not active`);
39
+ throw new common_1.UnauthorizedException('Your account is inactive. Please contact support.');
40
+ }
37
41
  return {
38
42
  id: user.id,
39
43
  email: user.email,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecrs-auth-core",
3
- "version": "1.0.82",
3
+ "version": "1.0.83",
4
4
  "description": "Centralized authentication and authorization module for ECRS apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",