Skip to main content

Function: getToken()

function getToken(input?, options?): Promise<Session | string | null>

Extracts the Auth.js session token derived from the provided context.

Parameters

ParameterTypeDescription
input?anyIncoming request or headers whose cookies contain the Auth.js session token.
options?objectSet raw to true to receive the unparsed cookie value instead of a decoded JWT payload.
options.raw?boolean-

Returns

Promise<Session | string | null>

The decoded JWT, the raw cookie value, or null if no token could be resolved.

Examples

const token = await getToken(request, { raw: true })
const payload = await getToken(headers, { raw: false })