[{"data":1,"prerenderedAt":450,"buildId":451},["ShallowReactive",2],{"docs-navigation-en":3,"examples-en":50,"page-\u002Fdocs\u002Fpublic-routes":237,"surround-\u002Fdocs\u002Fpublic-routes":445},[4],{"title":5,"path":6,"stem":7,"children":8,"page":49},"Docs","\u002Fdocs","docs",[9,13,17,21,25,29,33,37,41,45],{"title":10,"path":11,"stem":12},"Getting started","\u002Fdocs\u002Fgetting-started","docs\u002F01.getting-started",{"title":14,"path":15,"stem":16},"verifyUser","\u002Fdocs\u002Fverify-user","docs\u002F02.verify-user",{"title":18,"path":19,"stem":20},"Sites without users","\u002Fdocs\u002Fsites-without-users","docs\u002F03.sites-without-users",{"title":22,"path":23,"stem":24},"Build-time route check","\u002Fdocs\u002Froute-coverage","docs\u002F04.route-coverage",{"title":26,"path":27,"stem":28},"Public routes","\u002Fdocs\u002Fpublic-routes","docs\u002F05.public-routes",{"title":30,"path":31,"stem":32},"Same-origin writes","\u002Fdocs\u002Fsame-origin","docs\u002F06.same-origin",{"title":34,"path":35,"stem":36},"Scope and caching","\u002Fdocs\u002Fscope","docs\u002F07.scope",{"title":38,"path":39,"stem":40},"Configuration","\u002Fdocs\u002Fconfiguration","docs\u002F08.configuration",{"title":42,"path":43,"stem":44},"Migrating an existing BFF guard","\u002Fdocs\u002Fmigration","docs\u002F09.migration",{"title":46,"path":47,"stem":48},"Contributing","\u002Fdocs\u002Fcontributing","docs\u002F10.contributing",false,[51,61,69,77,83,90,98,106,113,122,131,138,146,153,159,166,174,180,188,194,202,208,215,221,229],{"path":52,"title":53,"description":54,"category":55,"order":56,"uses":57},"\u002Fexamples\u002Fcontact-form","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.","visitor",1,[58,59,60],"access: 'visitor'","@nuxtjs\u002Fturnstile","nuxt-security",{"path":62,"title":63,"description":64,"category":55,"order":65,"uses":66},"\u002Fexamples\u002Fpaid-api-proxy","Search box that calls a paid API","Keep other sites and scripts from spending your API quota through your BFF.",2,[58,67,68],"rateLimiter","defineCachedFunction",{"path":70,"title":71,"description":72,"category":55,"order":73,"uses":74},"\u002Fexamples\u002Fclient-data","JSON for client-side pages","Data that your pages fetch in the browser, kept from being embedded by other sites.",3,[58,75,76],"access: 'public'","useFetch",{"path":78,"title":79,"description":80,"category":55,"order":81,"uses":82},"\u002Fexamples\u002Fmember-site-contact","Visitor routes inside a member app","Keep 'user' as the default and open a few routes to visitors without accounts.",4,[58,14],{"path":84,"title":85,"description":86,"category":87,"order":56,"uses":88},"\u002Fexamples\u002Fnuxt-auth-utils","nuxt-auth-utils","Use the sealed Cookie session of nuxt-auth-utils as the user check.","auth",[85,89],"requireUserSession",{"path":91,"title":92,"description":93,"category":87,"order":65,"uses":94},"\u002Fexamples\u002Fsidebase-nuxt-auth","Auth.js with @sidebase\u002Fnuxt-auth","Check the Auth.js session, and accept the same JWT as a Bearer token.",[95,96,97],"@sidebase\u002Fnuxt-auth","getServerSession","getToken",{"path":99,"title":100,"description":101,"category":87,"order":73,"uses":102},"\u002Fexamples\u002Fsupabase","Supabase","Verify the Supabase session with getClaims, and tell bad tokens from outages.",[103,104,105],"@nuxtjs\u002Fsupabase","getClaims","isAuthRetryableFetchError",{"path":107,"title":108,"description":109,"category":87,"order":81,"uses":110},"\u002Fexamples\u002Fclerk","Clerk","Read the auth object that Clerk's middleware put on the event.",[111,112],"@clerk\u002Fnuxt","event.context.auth",{"path":114,"title":115,"description":116,"category":87,"order":117,"uses":118},"\u002Fexamples\u002Ffirebase","Firebase Authentication","Session Cookies for the browser, ID tokens for apps, and error codes mapped to 401 or 503.",5,[119,120,121],"firebase-admin","verifySessionCookie","verifyIdToken",{"path":123,"title":124,"description":125,"category":87,"order":126,"uses":127},"\u002Fexamples\u002Fjwt-jose","Any OpenID Connect provider (JWT)","Verify access tokens from Auth0, Keycloak, Cognito, Entra ID and others with jose.",6,[128,129,130],"jose","jwtVerify","createRemoteJWKSet",{"path":132,"title":133,"description":134,"category":135,"order":56,"uses":136},"\u002Fexamples\u002Fnuxt-security-rate-limit","Rate limits with nuxt-security","Slow down credential stuffing and token guessing before verifyUser runs.","security",[60,67,137],"routeRules",{"path":139,"title":140,"description":141,"category":135,"order":65,"uses":142},"\u002Fexamples\u002Fnuxt-security-headers","Headers, CSP and request limits with nuxt-security","A baseline nuxt-security setup next to the guard, tuned for a BFF.",[60,143,144,145],"headers","requestSizeLimiter","allowedMethodsRestricter",{"path":147,"title":148,"description":149,"category":135,"order":73,"uses":150},"\u002Fexamples\u002Fnuxt-csurf","CSRF tokens with nuxt-csurf","Add a synchronizer token on top of the origin check, without breaking Bearer clients.",[151,152,137],"nuxt-csurf","useCsrfFetch",{"path":154,"title":155,"description":156,"category":135,"order":81,"uses":157},"\u002Fexamples\u002Fturnstile","Bot checks on public routes with Turnstile","Public sign-in and sign-up routes skip verifyUser, so give them their own check.",[59,158],"verifyTurnstileToken",{"path":160,"title":161,"description":162,"category":135,"order":117,"uses":163},"\u002Fexamples\u002Fcors-bearer-clients","A frontend on another origin","CORS with nuxt-security for a separate app that calls the BFF with Bearer tokens.",[60,164,165],"corsHandler","viaBearer",{"path":167,"title":168,"description":169,"category":170,"order":56,"uses":171},"\u002Fexamples\u002Frecord-authorization","Per-record authorization","The guard says who the user is. The handler decides what they may touch.","patterns",[172,173],"event.context","createError",{"path":175,"title":176,"description":177,"category":170,"order":65,"uses":178},"\u002Fexamples\u002Froles","Roles and app-wide access","Reject whole groups of users in verifyUser, and check roles per route.",[14,179],"403",{"path":181,"title":182,"description":183,"category":170,"order":73,"uses":184},"\u002Fexamples\u002Fupstream-proxy","Calling an upstream API","Attach the user's token after the guard, never in middleware or routeRules.proxy.",[185,186,187],"$fetch","routeRules.proxy","server\u002Futils",{"path":189,"title":190,"description":191,"category":170,"order":81,"uses":192},"\u002Fexamples\u002Fssr-and-server-functions","SSR and server functions","Call your own API during server rendering, or skip HTTP entirely.",[76,193,187],"useRequestFetch",{"path":195,"title":196,"description":197,"category":170,"order":117,"uses":198},"\u002Fexamples\u002Fwebhooks","Webhooks","Server-to-server callbacks belong outside server\u002Fapi, with their own signature check.",[199,200,201],"server\u002Froutes","readRawBody","xssValidator",{"path":203,"title":204,"description":205,"category":170,"order":126,"uses":206},"\u002Fexamples\u002Fbearer-clients","Mobile apps and CLI tools","One BFF for the browser and for clients that send Bearer tokens.",[165,207],"Authorization",{"path":209,"title":210,"description":211,"category":170,"order":212,"uses":213},"\u002Fexamples\u002Fmore-route-folders","Checking more folders at build time","Extend routePatterns to server\u002Froutes and layers.",7,[214],"routePatterns",{"path":216,"title":217,"description":218,"category":170,"order":219,"uses":220},"\u002Fexamples\u002Fpublic-cache","Caching public data","Cache what is the same for everyone on a separate public route.",8,[68,75],{"path":222,"title":223,"description":224,"category":170,"order":225,"uses":226},"\u002Fexamples\u002Fclient-errors","Handling 401, 403 and 503 in the app","Sign out on 401, explain 403, retry on 503.",9,[227,228],"$fetch.create","onResponseError",{"path":230,"title":231,"description":232,"category":170,"order":233,"uses":234},"\u002Fexamples\u002Ftesting","Testing the protection","An end-to-end test that every protected route refuses anonymous calls.",10,[235,236],"@nuxt\u002Ftest-utils","vitest",{"id":238,"title":26,"body":239,"description":440,"extension":441,"meta":442,"navigation":294,"path":27,"seo":443,"stem":28,"__hash__":444},"docs_en\u002Fdocs\u002F05.public-routes.md",{"type":240,"value":241,"toc":436},"minimark",[242,246,362,377,382,385,401,414,418,429,432],[243,244,245],"p",{},"Some routes must work before anyone is signed in. Mark them on the route itself:",[247,248,254],"pre",{"className":249,"code":250,"filename":251,"language":252,"meta":253,"style":253},"language-ts shiki shiki-themes material-theme-lighter github-light github-dark","import { defineBffHandler } from '#bff-guard'\n\nexport default defineBffHandler(() => ({ ok: true }), { access: 'public' })\n","server\u002Fapi\u002Fhealth.get.ts","ts","",[255,256,257,290,296],"code",{"__ignoreMap":253},[258,259,261,265,269,273,276,279,283,287],"span",{"class":260,"line":56},"line",[258,262,264],{"class":263},"sVHd0","import",[258,266,268],{"class":267},"sP7_E"," {",[258,270,272],{"class":271},"su5hD"," defineBffHandler",[258,274,275],{"class":267}," }",[258,277,278],{"class":263}," from",[258,280,282],{"class":281},"sjJ54"," '",[258,284,286],{"class":285},"s_sjI","#bff-guard",[258,288,289],{"class":281},"'\n",[258,291,292],{"class":260,"line":65},[258,293,295],{"emptyLinePlaceholder":294},true,"\n",[258,297,298,301,304,307,310,313,317,320,323,327,330,334,336,339,342,344,347,349,351,354,357,359],{"class":260,"line":73},[258,299,300],{"class":263},"export",[258,302,303],{"class":263}," default",[258,305,272],{"class":306},"sGLFI",[258,308,309],{"class":271},"(",[258,311,312],{"class":267},"()",[258,314,316],{"class":315},"sbsja"," =>",[258,318,319],{"class":271}," (",[258,321,322],{"class":267},"{",[258,324,326],{"class":325},"skxfh"," ok",[258,328,329],{"class":267},":",[258,331,333],{"class":332},"syTEX"," true",[258,335,275],{"class":267},[258,337,338],{"class":271},")",[258,340,341],{"class":267},",",[258,343,268],{"class":267},[258,345,346],{"class":325}," access",[258,348,329],{"class":267},[258,350,282],{"class":281},[258,352,353],{"class":285},"public",[258,355,356],{"class":281},"'",[258,358,275],{"class":267},[258,360,361],{"class":271},")\n",[243,363,364,365,367,368,371,372,376],{},"A public route does not call ",[255,366,14],{},". It still sets ",[255,369,370],{},"Cache-Control: private, no-store",", and its writes still need the ",[373,374,375],"a",{"href":31},"same-origin check",".",[378,379,381],"h2",{"id":380},"finding-the-routes-that-must-be-public","Finding the routes that must be public",[243,383,384],{},"Walk through your sign-in flow with a fresh browser profile: no Cookie yet, a deleted Cookie, an expired Cookie. Every API the flow calls in those states must be public. Typical examples:",[386,387,388,392,395,398],"ul",{},[389,390,391],"li",{},"a route that exchanges an ID token for a session Cookie",[389,393,394],{},"sign-out, which must work with an expired session",[389,396,397],{},"health and readiness checks",[389,399,400],{},"data that pages load during server-side rendering, which anyone can read by opening the page",[243,402,403,404,407,408,411,412,376],{},"Webhooks from other servers are different: they send no ",[255,405,406],{},"Origin",", so the same-origin check rejects their POSTs. Put them outside ",[255,409,410],{},"server\u002Fapi","; see ",[373,413,196],{"href":195},[378,415,417],{"id":416},"rules-for-public-routes","Rules for public routes",[386,419,420,423,426],{},[389,421,422],{},"Do the route's own verification: an ID token, a bot check.",[389,424,425],{},"Return only data that may be public.",[389,427,428],{},"Keep public routes small. Do not route from a public catch-all into protected logic; the public flag belongs to that one handler.",[243,430,431],{},"The setting is bound to the handler, not to a path. A change in path normalization cannot move it to another route.",[433,434,435],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .syTEX, html code.shiki .syTEX{--shiki-light:#FF5370;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":253,"searchDepth":65,"depth":65,"links":437},[438,439],{"id":380,"depth":65,"text":381},{"id":416,"depth":65,"text":417},"Health checks, sign-in entry points and other routes without a user.","md",{},{"title":26,"description":440},"WZXbTEgcR1yDe5HceeYngSS_1pQeYRbQHLSHbYRKb4g",[446,448],{"title":22,"path":23,"stem":24,"description":447,"children":-1},"How the build finds routes that forgot defineBffHandler.",{"title":30,"path":31,"stem":32,"description":449,"children":-1},"How the guard blocks cross-site request forgery for Cookie-based writes.",1796451485264,"a99f93bd-e267-45a7-90df-9194cd77468d"]