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:
Mathis H (Avnyr) 2024-07-24 20:26:53 +02:00
parent b8a472bfcd
commit b558d344e1
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -22,8 +22,10 @@ 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 {
const result = await jose.jwtVerify(
token, token,
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")), Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
{ {
@ -31,6 +33,12 @@ export class CredentialsService {
issuer: "ShouldStick", 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) {