Bun

namespace

CSRF

namespace CSRF

Generate and verify CSRF tokens

  • function generate(
    secret?: string,
    ): string;

    Generate a CSRF token.

    @param secret

    The secret to use for the token. If not provided, a random default secret will be generated in memory and used.

    @param options

    The options for the token.

    @returns

    The generated token.

  • 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.