Inspect authenticated token claims
Read claims from an Auth.js JWT on the server after obtaining the token and required decoding configuration.
Auth.js · Function
decode asynchronously decodes an Auth.js-issued JWT. It returns the decoded payload or null, and supports a generic payload type.
Call decode with JWT decoding parameters, typically the token and secret. It asynchronously returns either the decoded payload or null when decoding does not produce a payload; the generic type can describe a custom payload shape.
function decode<Payload>(params): Promise<null | Payload>| Name | Type | Description |
|---|---|---|
params | JWTDecodeParams | Object containing the inputs required to decode the token. |
Promise<null | Payload>
JWT type when no custom type is supplied.import { decode } from "@auth/core/jwt"
const payload = await decode({
token: process.env.AUTH_TOKEN,
secret: process.env.AUTH_SECRET,
})
if (payload) {
console.log(payload.sub)
}Decodes an Auth.js JWT and uses the returned payload when decoding succeeds.
Read claims from an Auth.js JWT on the server after obtaining the token and required decoding configuration.
Supply a custom payload type when application-specific JWT claims are known.
Replace the default JWT decoding behavior through Auth.js configuration.
decode return?decode accepts a JWTDecodeParams object and returns Promise<null | Payload>. Its purpose is to decode an Auth.js-issued JWT, with Payload defaulting to JWT.
Follow-up: How should a caller handle failure? Check whether the promise resolves to null before reading payload fields.
decode accept?The required argument is the params object, whose type is JWTDecodeParams. The object supplies the information needed by the Auth.js JWT decoder.
Follow-up: What is the advantage of passing a parameter object? It keeps the API extensible and makes each decoding input explicit.
Auth.js exposes a configurable decode method that can be overridden to control how issued JWTs are decoded. A custom implementation must remain compatible with the expected asynchronous result and payload contract.
Follow-up: What contract must a replacement preserve? It should accept the configured decode parameters and resolve to either a payload or null.
JWTDecodeParamsJWTencode