auth Hook
Type: onRequestHookHandler
Access: nauth.middleware.auth
Validates JWT access token and stores authenticated user in context.
Signature
(request: FastifyRequest, reply: FastifyReply) => Promise<void>
Registration
fastify.addHook('onRequest', nauth.middleware.auth);
Behavior
- Extracts token from
Authorization: Bearer <token>header or cookies - Validates token signature and expiration
- Stores user in AsyncLocalStorage context
- Does not reject unauthenticated requests (use
requireAuth()helper)