tokenDelivery Hook
Type: onSendHookHandler
Access: nauth.middleware.tokenDelivery
Intercepts responses to set authentication cookies.
Signature
(request: FastifyRequest, reply: FastifyReply, payload: unknown) => Promise<unknown>
Registration
fastify.addHook('onSend', nauth.middleware.tokenDelivery);
Behavior
- Detects
AuthResponseDTOin response body - Sets
accessTokenandrefreshTokencookies based on delivery mode - Removes tokens from JSON body when using cookie delivery
- Sets CSRF token cookie
Cookie Options
Configured via config.cookies:
| Option | Type | Description |
|---|---|---|
secure | boolean | HTTPS only |
httpOnly | boolean | No JS access |
sameSite | string | CSRF protection |
domain | string | Cookie domain |