Skip to main content

jwt

Not recommended

In NextAuth.js v5 or newer, we recommend other authentication methods server-side. Read more at: https://authjs.dev/guides/upgrade-to-v5#authenticating-server-side

decode()​

decode<Payload>(params): Promise< Payload | null >

Decodes a Auth.js issued JWT.

Type parameters​

β–ͺ Payload = JWT

Parameters​

β–ͺ params: JWTDecodeParams

Returns​

Promise< Payload | null >


encode()​

encode<Payload>(params): Promise< string >

Issues a JWT. By default, the JWT is encrypted using "A256GCM".

Type parameters​

β–ͺ Payload = JWT

Parameters​

β–ͺ params: JWTEncodeParams< Payload >

Returns​

Promise< string >


getToken()​

getToken<R>(params): Promise< R extends true ? string : JWT | null >

Takes an Auth.js request (req) and returns either the Auth.js issued JWT's payload, or the raw JWT string. We look for the JWT in the either the cookies, or the Authorization header.

Type parameters​

β–ͺ R extends boolean = false

Parameters​

β–ͺ params: GetTokenParams< R >

Returns​

Promise< R extends true ? string : JWT | null >


JWT​

Returned by the jwt callback and getToken, when using JWT sessions

jwt callback | getToken

Extends​

  • Record< string, unknown >.DefaultJWT