Skip to content

Commit

Permalink
🚑 Try fixing identical JWT generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jan 6, 2024
1 parent bddd81b commit 8fa1b0b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/auth/models/models/at-payload.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {TokenType} from "./token-type";
export class AtPayloadModel{
user_id: number;
type: TokenType;
random: string;

constructor(userId: number){
constructor(userId: number, random: string){
this.user_id = userId;
this.type = TokenType.ACCESS;
this.random = random;
}
}
4 changes: 3 additions & 1 deletion src/auth/models/models/rt-payload.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {TokenType} from "./token-type";
export class RtPayloadModel{
user_id: number;
type: TokenType;
random: string;

constructor(userId: number){
constructor(userId: number, random: string){
this.user_id = userId;
this.type = TokenType.REFRESH;
this.random = random;
}
}
4 changes: 2 additions & 2 deletions src/services/tokens.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TokensService{
){}

async generateAccessToken(userId: number): Promise<string>{
const payload = new AtPayloadModel(userId);
const payload = new AtPayloadModel(userId, this.encryptionService.generateSecret());
const token = this.jwtService.generateJWT({...payload}, this.configService.get("AT_DURATION"), this.configService.get("AT_KEY"));
const expires = (<any>this.jwtService.decodeJwt(token)).exp;
const sum = this.encryptionService.getSum(token).substring(0, 10);
Expand All @@ -36,7 +36,7 @@ export class TokensService{
}

async generateRefreshToken(userId: number): Promise<string>{
const payload = new RtPayloadModel(userId);
const payload = new RtPayloadModel(userId, this.encryptionService.generateSecret());
const token = this.jwtService.generateJWT({...payload}, this.configService.get("RT_DURATION"), this.configService.get("RT_KEY"));
const expires = (<any>this.jwtService.decodeJwt(token)).exp;
const sum = this.encryptionService.getSum(token).substring(0, 10);
Expand Down

0 comments on commit 8fa1b0b

Please sign in to comment.