fix auth token expiration

This commit is contained in:
2025-12-03 11:50:16 +03:30
parent ae9aa72c44
commit e8566aa389
2 changed files with 15 additions and 8 deletions
+7 -3
View File
@@ -18,13 +18,17 @@ import { RefreshToken } from './entities/refresh-token.entity';
UtilsModule, UtilsModule,
forwardRef(() => UserModule), forwardRef(() => UserModule),
JwtModule.registerAsync({ JwtModule.registerAsync({
useFactory: (configService: ConfigService) => ({ useFactory: (configService: ConfigService) => {
const expiresIn = configService.getOrThrow<number>('JWT_EXPIRATION_TIME');
return {
global: true, global: true,
secret: configService.getOrThrow<string>('JWT_SECRET'), secret: configService.getOrThrow<string>('JWT_SECRET'),
signOptions: { signOptions: {
expiresIn: configService.getOrThrow<number>('JWT_EXPIRATION_TIME'), // Use string format with time unit for explicit expiration (value should be in seconds)
expiresIn: `${expiresIn}s`,
},
};
}, },
}),
inject: [ConfigService], inject: [ConfigService],
}), }),
forwardRef(() => AdminModule), forwardRef(() => AdminModule),
+4 -1
View File
@@ -39,7 +39,10 @@ export class TokensService {
} }
private generateAccessToken(payload: ITokenPayload | IAdminTokenPayload, expiresIn: number) { 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) { async storeRefreshToken(ownerId: string, restId: string, refreshToken: string, type: RefreshTokenType) {