diff --git a/src/modules/auth/auth.module.ts b/src/modules/auth/auth.module.ts index d4cab82..a7519cc 100644 --- a/src/modules/auth/auth.module.ts +++ b/src/modules/auth/auth.module.ts @@ -18,13 +18,17 @@ import { RefreshToken } from './entities/refresh-token.entity'; UtilsModule, forwardRef(() => UserModule), JwtModule.registerAsync({ - useFactory: (configService: ConfigService) => ({ - global: true, - secret: configService.getOrThrow('JWT_SECRET'), - signOptions: { - expiresIn: configService.getOrThrow('JWT_EXPIRATION_TIME'), - }, - }), + useFactory: (configService: ConfigService) => { + const expiresIn = configService.getOrThrow('JWT_EXPIRATION_TIME'); + return { + global: true, + secret: configService.getOrThrow('JWT_SECRET'), + signOptions: { + // Use string format with time unit for explicit expiration (value should be in seconds) + expiresIn: `${expiresIn}s`, + }, + }; + }, inject: [ConfigService], }), forwardRef(() => AdminModule), diff --git a/src/modules/auth/services/tokens.service.ts b/src/modules/auth/services/tokens.service.ts index 606b8dc..5bdf798 100755 --- a/src/modules/auth/services/tokens.service.ts +++ b/src/modules/auth/services/tokens.service.ts @@ -39,7 +39,10 @@ export class TokensService { } private generateAccessToken(payload: ITokenPayload | IAdminTokenPayload, expiresIn: number) { - return this.jwtService.signAsync(payload, { expiresIn }); + // Ensure expiresIn is passed as a string with time unit for reliability + // JWT library accepts: number (seconds) or string with unit (e.g., "3600s", "1h") + // Using string format is more explicit and prevents unit confusion + return this.jwtService.signAsync(payload, { expiresIn: `${expiresIn}s` }); } async storeRefreshToken(ownerId: string, restId: string, refreshToken: string, type: RefreshTokenType) {