Decodes a NextAuth.js issued JWT.
(token: string)
| 22 | |
| 23 | /** Decodes a NextAuth.js issued JWT. */ |
| 24 | async function decode(token: string): Promise<JwtPayload | null> { |
| 25 | if (!token) return null; |
| 26 | const encryptionSecret = await getDerivedEncryptionKey( |
| 27 | process.env.NEXTAUTH_SECRET! |
| 28 | ); |
| 29 | const { payload } = await jose.jwtDecrypt(token, encryptionSecret, { |
| 30 | clockTolerance: 15, |
| 31 | }); |
| 32 | return payload as JwtPayload; |
| 33 | } |
| 34 | |
| 35 | async function getDerivedEncryptionKey(secret: string | Buffer) { |
| 36 | return await hkdf('sha256', secret, '', 'Linen Generated Encryption Key', 32); |
no test coverage detected