@buntal/core - Middleware

auth

JWT-based authentication middleware for Buntal applications that validates tokens from cookies or headers.

Source

View source on GitHub

Type Definition

function auth<T = unknown>(options?: AuthOptions<T>): AtomicHandler<Record<string, string>, T>

type AuthOptions<T = unknown> = {
  secret: string
  strategy?: 'cookie' | 'header' | 'both'
  cookie?: { key: string }
  header?: { key: string }
  onVerified?: (req: Req<Record<string, string>, T>, res: Res, decoded: T) => void | Response | Promise<void | Response>
}

Parameters

ParameterTypeRequiredDefaultDescription
optionsAuthOptions<T>-Authentication configuration options

Properties

PropertyTypeRequiredDefaultDescription
secretstringprocess.env.JWT_SECRETSecret key for JWT verification
strategy'cookie' | 'header' | 'both'headerToken extraction strategy
cookie{ key: string }{ key: "access_token" }Cookie configuration for token extraction
header{ key: string }{ key: "Authorization" }Header configuration for token extraction
onVerifiedfunction-Callback function called after successful token verification

Last modified: 2025-06-10

Content-Length: 0