function

CSRF.verify

function verify(
token: string,
): boolean;

Verify a CSRF token.

@param token

The token to verify.

@param options

The options for the token.

@returns

True if the token is valid, false otherwise.

Referenced types

interface CSRFVerifyOptions

  • algorithm?: CSRFAlgorithm

    The algorithm to use for the token.

  • encoding?: 'base64' | 'base64url' | 'hex'

    The encoding of the token.

  • maxAge?: number

    The number of milliseconds until the token expires. 0 means the token never expires.

  • secret?: string

    The secret to use for the token. If not provided, Bun generates a random default secret in memory and uses it.

  • sessionId?: string

    The principal (session ID, user ID, or equivalent) the token must be bound to. A token generated with a sessionId only verifies when the same sessionId is supplied here; a token generated without one only verifies when this option is omitted.