fix(credentials): handle token verification errors
Added try-catch block in verifyAuthToken to handle and log JWT verification errors. This change ensures that invalid tokens are caught and a relevant BadRequestException is thrown.
This commit is contained in:
parent
b8a472bfcd
commit
b558d344e1
@ -22,15 +22,23 @@ export class CredentialsService {
|
|||||||
secret: Buffer.from(this.configService.get("APP_HASH_SECRET")),
|
secret: Buffer.from(this.configService.get("APP_HASH_SECRET")),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async verifyAuthToken(token: string) {
|
async verifyAuthToken(token: string) {
|
||||||
return await jose.jwtVerify(
|
try {
|
||||||
token,
|
const result = await jose.jwtVerify(
|
||||||
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
|
token,
|
||||||
{
|
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
|
||||||
audience: "auth:user",
|
{
|
||||||
issuer: "ShouldStick",
|
audience: "auth:user",
|
||||||
},
|
issuer: "ShouldStick",
|
||||||
);
|
},
|
||||||
|
);
|
||||||
|
console.log(result);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
throw new BadRequestException("Invalid token");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async signAuthToken(payload: JWTPayload) {
|
async signAuthToken(payload: JWTPayload) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user