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
JSON for client-side pages
Data that your pages fetch in the browser, kept from being embedded by other sites.
access: 'visitor'access: 'public'useFetch
Visitor routes inside a member app
Keep 'user' as the default and open a few routes to visitors without accounts.
access: 'visitor'verifyUser

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
Clerk
Read the auth object that Clerk's middleware put on the event.
@clerk/nuxtevent.context.auth
Firebase Authentication
Session Cookies for the browser, ID tokens for apps, and error codes mapped to 401 or 503.
firebase-adminverifySessionCookieverifyIdToken
Any OpenID Connect provider (JWT)
Verify access tokens from Auth0, Keycloak, Cognito, Entra ID and others with jose.
josejwtVerifycreateRemoteJWKSet

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
Bot checks on public routes with Turnstile
Public sign-in and sign-up routes skip verifyUser, so give them their own check.
@nuxtjs/turnstileverifyTurnstileToken
A frontend on another origin
CORS with nuxt-security for a separate app that calls the BFF with Bearer tokens.
nuxt-securitycorsHandlerviaBearer

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
Checking more folders at build time
Extend routePatterns to server/routes and layers.
routePatterns
Caching public data
Cache what is the same for everyone on a separate public route.
defineCachedFunctionaccess: 'public'
Handling 401, 403 and 503 in the app
Sign out on 401, explain 403, retry on 503.
$fetch.createonResponseError
Testing the protection
An end-to-end test that every protected route refuses anonymous calls.
@nuxt/test-utilsvitest