Examples
Complete files for sites without users, common auth providers, security modules and BFF patterns.
Sites without users
Contact forms, paid API proxies and client-side data on sites without accounts.
Contact form on a corporate site
A mail-sending route that only your own pages can call, with a bot check and a rate limit.
access: 'visitor'@nuxtjs/turnstilenuxt-security
Search box that calls a paid API
Keep other sites and scripts from spending your API quota through your BFF.
access: 'visitor'rateLimiterdefineCachedFunction
Auth providers
verifyUser for nuxt-auth-utils, Auth.js, Supabase, Clerk, Firebase and plain JWT.
nuxt-auth-utils
Use the sealed Cookie session of nuxt-auth-utils as the user check.
nuxt-auth-utilsrequireUserSession
Auth.js with @sidebase/nuxt-auth
Check the Auth.js session, and accept the same JWT as a Bearer token.
@sidebase/nuxt-authgetServerSessiongetToken
Supabase
Verify the Supabase session with getClaims, and tell bad tokens from outages.
@nuxtjs/supabasegetClaimsisAuthRetryableFetchError
Security modules
Rate limits, headers, CSP, CSRF tokens, bot checks and CORS next to the guard.
Rate limits with nuxt-security
Slow down credential stuffing and token guessing before verifyUser runs.
nuxt-securityrateLimiterrouteRules
Headers, CSP and request limits with nuxt-security
A baseline nuxt-security setup next to the guard, tuned for a BFF.
nuxt-securityheadersrequestSizeLimiterallowedMethodsRestricter
CSRF tokens with nuxt-csurf
Add a synchronizer token on top of the origin check, without breaking Bearer clients.
nuxt-csurfuseCsrfFetchrouteRules
BFF patterns
Sign-in routes, webhooks, upstream proxies, roles, SSR calls and more.
Per-record authorization
The guard says who the user is. The handler decides what they may touch.
event.contextcreateError
Roles and app-wide access
Reject whole groups of users in verifyUser, and check roles per route.
verifyUser403
Calling an upstream API
Attach the user's token after the guard, never in middleware or routeRules.proxy.
$fetchrouteRules.proxyserver/utils
SSR and server functions
Call your own API during server rendering, or skip HTTP entirely.
useFetchuseRequestFetchserver/utils
Webhooks
Server-to-server callbacks belong outside server/api, with their own signature check.
server/routesreadRawBodyxssValidator
Mobile apps and CLI tools
One BFF for the browser and for clients that send Bearer tokens.
viaBearerAuthorization
Caching public data
Cache what is the same for everyone on a separate public route.
defineCachedFunctionaccess: 'public'