JWT Signature Verification Failed #1496
Answered
by
StefanSelfTaught
jackmerrill
asked this question in
Help
-
Hi there! I'm using JWT for my authentication method here, and I have the Next-Auth JWT settings set correctly, with both the signingKey and secret, and it should all be valid.
jwt: {
signingKey: '{"kty":"oct","kid":"...","alg":"HS512","k":"..."}',
secret: process.env.JWT_TOKEN,
},
// getServerSideProps
const r = req as NextApiRequest;
const raw = await jwt.getToken({ req: r, raw: true });
const token = await jwt.decode({
token: raw,
secret: process.env.JWT_TOKEN,
}) as JWTSession;
if (!token || token === null) {
return {
redirect: {
permanent: false,
destination: '/auth/login',
},
};
} Any help to fix this issue is appreciated, as well as any better methods I should be using. Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
StefanSelfTaught
Mar 11, 2021
Replies: 1 comment 3 replies
-
const token = await jwt.getToken({ req, secret: process.env.JWT_TOKEN, encryptionKey: 'key', signingKey: 'key' }) |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
balazsorban44
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jwt.getToken()
can decode the token for you. If you specified asigningKey
you probably want to also add anencryptionKey
and you should also pass thekeys
or any other options that you have in your jwt settings.