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,8 +22,10 @@ export class CredentialsService {
|
||||
secret: Buffer.from(this.configService.get("APP_HASH_SECRET")),
|
||||
});
|
||||
}
|
||||
|
||||
async verifyAuthToken(token: string) {
|
||||
return await jose.jwtVerify(
|
||||
try {
|
||||
const result = await jose.jwtVerify(
|
||||
token,
|
||||
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
|
||||
{
|
||||
@ -31,6 +33,12 @@ export class CredentialsService {
|
||||
issuer: "ShouldStick",
|
||||
},
|
||||
);
|
||||
console.log(result);
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
throw new BadRequestException("Invalid token");
|
||||
}
|
||||
}
|
||||
|
||||
async signAuthToken(payload: JWTPayload) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user