Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Use object payload for JWT
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Oct 30, 2020
1 parent 7f53c14 commit 97096b3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class AuthService {
'frontendUrl',
)}/auth/verify-email?token=${this.tokensService.signJwt(
EMAIL_VERIFY_TOKEN,
emailDetails.user.id,
{ id: emailDetails.user.id },
'7d',
)}`,
},
Expand Down Expand Up @@ -238,7 +238,10 @@ export class AuthService {
token: string,
): Promise<TokenResponse> {
if (!token) throw new UnprocessableEntityException();
const id = this.tokensService.verify<number>(APPROVE_SUBNET_TOKEN, token);
const { id } = this.tokensService.verify<{ id: number }>(
APPROVE_SUBNET_TOKEN,
token,
);
await this.approvedSubnetsService.approveNewSubnet(id, ipAddress);
return this.loginResponse(ipAddress, userAgent, id);
}
Expand Down Expand Up @@ -330,7 +333,7 @@ export class AuthService {
'frontendUrl',
)}/auth/reset-password?token=${this.tokensService.signJwt(
PASSWORD_RESET_TOKEN,
emailDetails.user.id,
{ id: emailDetails.user.id },
'30m',
)}`,
},
Expand All @@ -345,7 +348,10 @@ export class AuthService {
password: string,
ignorePwnedPassword?: boolean,
): Promise<TokenResponse> {
const id = this.tokensService.verify<number>(PASSWORD_RESET_TOKEN, token);
const { id } = this.tokensService.verify<{ id: number }>(
PASSWORD_RESET_TOKEN,
token,
);
password = await this.hashAndValidatePassword(
password,
!!ignorePwnedPassword,
Expand All @@ -356,7 +362,10 @@ export class AuthService {
}

async verifyEmail(token: string): Promise<Expose<emails>> {
const id = this.tokensService.verify<number>(EMAIL_VERIFY_TOKEN, token);
const { id } = this.tokensService.verify<{ id: number }>(
EMAIL_VERIFY_TOKEN,
token,
);
const result = await this.prisma.emails.update({
where: { id },
data: { isVerified: true },
Expand Down Expand Up @@ -478,7 +487,7 @@ export class AuthService {
'frontendUrl',
)}/auth/token-login?token=${this.tokensService.signJwt(
EMAIL_MFA_TOKEN,
user.id,
{ id: user.id },
'30m',
)}`,
},
Expand Down Expand Up @@ -529,7 +538,7 @@ export class AuthService {
'frontendUrl',
)}/auth/reset-password?token=${this.tokensService.signJwt(
APPROVE_SUBNET_TOKEN,
id,
{ id },
'30m',
)}`,
},
Expand Down

0 comments on commit 97096b3

Please sign in to comment.