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,15 +22,23 @@ export class CredentialsService {
secret: Buffer.from(this.configService.get("APP_HASH_SECRET")),
});
}
async verifyAuthToken(token: string) {
return await jose.jwtVerify(
token,
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
{
audience: "auth:user",
issuer: "ShouldStick",
},
);
try {
const result = await jose.jwtVerify(
token,
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
{
audience: "auth:user",
issuer: "ShouldStick",
},
);
console.log(result);
return result;
} catch (error) {
console.log(error)
throw new BadRequestException("Invalid token");
}
}
async signAuthToken(payload: JWTPayload) {