Configuration
All options of the bffGuard key.
nuxt.config.ts
export default defineNuxtConfig({
modules: ['@kurashina-design/nuxt-bff-guard'],
bffGuard: {
access: 'user',
verifyUser: './server/auth/verify-user.ts',
routePatterns: ['server/api/**'],
writeMethods: ['POST', 'PUT', 'PATCH', 'DELETE'],
},
})
| Option | Default | Description |
|---|---|---|
access | 'user' | Default protection of every route: 'user' or 'visitor'. See Sites without users. |
verifyUser | none | Server file whose default export is the verifyUser function. Relative to the project root, or absolute. Required in production when access is 'user'. |
routePatterns | ['server/api/**'] | Globs of route files that must use defineBffHandler. Your array replaces the default. See Build-time route check. |
writeMethods | ['POST', 'PUT', 'PATCH', 'DELETE'] | Methods that need the same-origin check. |
defineBffHandler
import { defineBffHandler } from '#bff-guard'
defineBffHandler(handler, { access?: 'user' | 'visitor' | 'public' })
| Option | Default | Description |
|---|---|---|
access | the access option | 'user': verifyUser and the same-origin check for writes. 'visitor': only fetches from your own pages (Sec-Fetch-Site: same-origin), every method. 'public': no user check; writes still need your origin. Cache-Control applies to all. |
Responses
| Status | When |
|---|---|
| 401 | verifyUser is missing, returned something invalid, or threw a 4xx other than 403. |
| 403 | verifyUser threw 403, a write failed the same-origin check, or a visitor route got anything but a fetch from your own pages. |
| 503 | verifyUser threw an error without a 4xx statusCode. |
Every response from a wrapped handler gets Cache-Control: private, no-store.
Startup errors
verifyUser is required in production: setverifyUser, oraccess: 'visitor'if the site has no accounts.Legacy configuration detected: removeapiPrefix,publicPathsandinternalRequestsfrom an older version. See Migration.Nitro 2 is required: the module does not support Nitro 3 yet.