@ackplus/nest-auth 1.1.21 → 1.1.22

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ackplus/nest-auth",
3
- "version": "1.1.21",
3
+ "version": "1.1.22",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
@@ -9,7 +9,7 @@ import { SignupRequestDto } from '../dto/requests/signup.request.dto';
9
9
  import { AuthResponseDto } from '../dto/responses/auth.response.dto';
10
10
  import { LoginRequestDto } from '../dto/requests/login.request.dto';
11
11
  import { Verify2faRequestDto } from '../dto/requests/verify-2fa.request.dto';
12
- import { MFAMethodEnum } from '../../core/interfaces/mfa-options.interface';
12
+ import { MFAMethodEnum, MFAOptions } from '../../core/interfaces/mfa-options.interface';
13
13
  import { ForgotPasswordRequestDto } from '../dto/requests/forgot-password.request.dto';
14
14
  import { ResetPasswordRequestDto } from '../dto/requests/reset-password.request.dto';
15
15
  import { AuthProviderRegistryService } from '../../core/services/auth-provider-registry.service';
@@ -37,6 +37,7 @@ export declare class AuthService {
37
37
  private readonly authConfigService;
38
38
  private readonly userService;
39
39
  constructor(userRepository: Repository<NestAuthUser>, otpRepository: Repository<NestAuthOTP>, authProviderRegistry: AuthProviderRegistryService, mfaService: MfaService, sessionManager: SessionManagerService, jwtService: JwtService, eventEmitter: EventEmitter2, tenantService: TenantService, debugLogger: DebugLoggerService, authConfigService: AuthConfigService, userService: UserService);
40
+ get mfaConfig(): MFAOptions;
40
41
  getUserWithRolesAndPermissions(userId: string, relations?: string[]): Promise<NestAuthUser>;
41
42
  getUser(): Promise<Partial<NestAuthUser>>;
42
43
  signup(input: SignupRequestDto): Promise<AuthResponseDto>;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../../../../../../packages/nest-auth/src/lib/auth/services/auth.service.ts"],"names":[],"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AAU,GAAE,MAAM,GAAG,OAAO,GAAG,QAAiB,EAAE,MAAM,CAAC,EAAE,MAAM;IAwBxE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAM,GAAG,OAAO,GAAG,QAAiB,EAAE,MAAM,CAAC,EAAE,MAAM;IAiC3F,qBAAqB,CAAC,KAAK,EAAE,+BAA+B;;;IA6D5D,WAAW,CAAC,KAAK,EAAE,qBAAqB;;;YAkFhC,qBAAqB;IAyBnC;;OAEG;IACH,OAAO,CAAC,WAAW;YAYL,yBAAyB;CAK1C"}
@@ -32,6 +32,7 @@ const auth_config_service_1 = require("../../core/services/auth-config.service")
32
32
  const cookie_helper_1 = require("../../utils/cookie.helper");
33
33
  const user_password_changed_event_1 = require("../events/user-password-changed.event");
34
34
  const user_service_1 = require("../../user/services/user.service");
35
+ const ms_1 = tslib_1.__importDefault(require("ms"));
35
36
  let AuthService = class AuthService {
36
37
  constructor(userRepository, otpRepository, authProviderRegistry, mfaService, sessionManager, jwtService, eventEmitter, tenantService, debugLogger, authConfigService, userService) {
37
38
  this.userRepository = userRepository;
@@ -46,6 +47,9 @@ let AuthService = class AuthService {
46
47
  this.authConfigService = authConfigService;
47
48
  this.userService = userService;
48
49
  }
50
+ get mfaConfig() {
51
+ return auth_config_service_1.AuthConfigService.getOptions().mfa || {};
52
+ }
49
53
  getUserWithRolesAndPermissions(userId, relations = []) {
50
54
  return this.userRepository.findOne({
51
55
  where: { id: userId },
@@ -514,17 +518,42 @@ let AuthService = class AuthService {
514
518
  // Return success even if user not found to prevent email/phone enumeration
515
519
  return { message: 'If the account exists, a password reset code has been sent' };
516
520
  }
517
- // Generate OTP
518
- const otp = (0, otp_1.generateOtp)();
519
- const expiresAt = new Date();
520
- expiresAt.setMinutes(expiresAt.getMinutes() + 15); // OTP expires in 15 minutes
521
- // Save OTP to database
522
- const otpEntity = await this.otpRepository.save({
521
+ const options = auth_config_service_1.AuthConfigService.getOptions();
522
+ let code;
523
+ // Apply otp.generate hook if configured
524
+ if (options.otp?.generate) {
525
+ code = await options.otp.generate(this.mfaConfig.otpLength);
526
+ }
527
+ else {
528
+ code = (0, otp_1.generateOtp)(this.mfaConfig.otpLength);
529
+ }
530
+ let expiresAtMs;
531
+ if (typeof this.mfaConfig.otpExpiresIn === 'string') {
532
+ expiresAtMs = (0, ms_1.default)(this.mfaConfig.otpExpiresIn); // example: '15m', '1h', '1d'
533
+ }
534
+ else {
535
+ expiresAtMs = this.mfaConfig.otpExpiresIn || 900000; // Default to 15m if undefined
536
+ }
537
+ if (!expiresAtMs || isNaN(expiresAtMs) || expiresAtMs <= 0) {
538
+ throw new Error(`Invalid MFA configuration: otpExpiresIn '${this.mfaConfig.otpExpiresIn}' results in invalid duration`);
539
+ }
540
+ // Invalidate previous MFA OTPs for this user
541
+ await this.otpRepository.delete({
523
542
  userId: identity.user?.id,
524
- code: otp,
525
- expiresAt,
526
543
  type: otp_interface_1.OTPTypeEnum.PASSWORD_RESET
527
544
  });
545
+ // // Generate OTP
546
+ // const otp = generateOtp();
547
+ // const expiresAt = new Date();
548
+ // expiresAt.setMinutes(expiresAt.getMinutes() + this.mfaConfig.otpExpiresIn); // OTP expires in 15 minutes
549
+ // Save OTP to database
550
+ const otpEntity = await this.otpRepository.create({
551
+ userId: identity.user?.id,
552
+ type: otp_interface_1.OTPTypeEnum.PASSWORD_RESET,
553
+ expiresAt: new Date(Date.now() + expiresAtMs),
554
+ code,
555
+ });
556
+ await this.otpRepository.save(otpEntity);
528
557
  // Emit refresh token event, Send OTP via email or SMS should be handled by the event listener
529
558
  await this.eventEmitter.emitAsync(auth_constants_1.NestAuthEvents.PASSWORD_RESET_REQUESTED, new password_reset_requested_event_1.PasswordResetRequestedEvent({
530
559
  user: identity.user,