const decodedToken = jwt.decode(token, { complete: true });
if (!decodedToken || typeof decodedToken === "string") {
throw new Error("Invalid token");
}
const kid = decodedToken.header.kid;
const signingKey = await getSigningKey(kid);
const publicKey = (
signingKey as jwksClient.CertSigningKey | jwksClient.RsaSigningKey
).getPublicKey();
console.log(EXPECTED_AUDIENCE);
const verified = jwt.verify(token, publicKey, {
algorithms: ["RS256"], // Specify the expected algorithm
audience: EXPECTED_AUDIENCE, // Verify the audience claim
});
// Verifying Email claim
if (!verified.email || typeof verified.email !== "string") {
throw new Error("Invalid email claim");
}