chore: change the refresh token service

This commit is contained in:
mahyargdz
2025-06-01 12:04:02 +03:30
parent 8d335429e2
commit bd40f349bf
+7 -1
View File
@@ -1,3 +1,5 @@
import { randomBytes } from "node:crypto";
import { Injectable, Logger, UnauthorizedException } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt";
@@ -39,7 +41,7 @@ export class TokensService {
const accessToken = this.jwtService.sign(payload, { expiresIn: `${accessExpire}h` });
const refreshToken = this.jwtService.sign({ id: payload.id }, { expiresIn: `${refreshExpire}d` });
const refreshToken = await this.generateRefreshToken();
await this.storeRefreshToken(payload.id, refreshToken, queryRunner);
@@ -118,4 +120,8 @@ export class TokensService {
await this.refreshTokensRepository.delete({ user: { id: userId } });
this.logger.log(`Successfully deleted all refresh tokens for user ${userId}`);
}
private async generateRefreshToken() {
return randomBytes(32).toString("hex");
}
}