auth
JWT-based authentication middleware for Buntal applications that validates tokens from cookies or headers.
Source
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
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
options | AuthOptions<T> | ❌ | - | Authentication configuration options |
Properties
Property | Type | Required | Default | Description |
---|---|---|---|---|
secret | string | ✅ | process.env.JWT_SECRET | Secret key for JWT verification |
strategy | 'cookie' | 'header' | 'both' | ❌ | header | Token extraction strategy |
cookie | { key: string } | ❌ | { key: "access_token" } | Cookie configuration for token extraction |
header | { key: string } | ❌ | { key: "Authorization" } | Header configuration for token extraction |
onVerified | function | ❌ | - | Callback function called after successful token verification |
Last modified: 2025-06-10