chore: change the refresh token service
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user