[{"data":1,"prerenderedAt":668,"buildId":669},["ShallowReactive",2],{"docs-navigation-en":3,"example-\u002Fexamples\u002Fmember-site-contact":50,"example-surround-\u002Fexamples\u002Fmember-site-contact":490,"examples-en":500},[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,{"id":51,"title":52,"body":53,"category":313,"description":481,"extension":482,"meta":483,"navigation":213,"order":140,"path":484,"seo":485,"stem":486,"uses":487,"__hash__":489},"examples_en\u002Fexamples\u002Fmember-site-contact.md","Visitor routes inside a member app",{"type":54,"value":55,"toc":479},"minimark",[56,64,178,320,392,465,475],[57,58,59,60,63],"p",{},"A SaaS app protects its API with ",[61,62,14],"code",{},", but its marketing pages have a demo request form and a pricing calculator for people who have not signed up yet.",[65,66,72],"pre",{"className":67,"code":68,"filename":69,"language":70,"meta":71,"style":71},"language-ts shiki shiki-themes material-theme-lighter github-light github-dark","export default defineNuxtConfig({\n  modules: ['@kurashina-design\u002Fnuxt-bff-guard'],\n  bffGuard: {\n    \u002F\u002F 'user' stays the default: every route needs a verified user unless it says otherwise.\n    verifyUser: '.\u002Fserver\u002Fauth\u002Fverify-user.ts',\n  },\n})\n","nuxt.config.ts","ts","",[61,73,74,98,127,138,145,163,169],{"__ignoreMap":71},[75,76,79,83,86,90,94],"span",{"class":77,"line":78},"line",1,[75,80,82],{"class":81},"sVHd0","export",[75,84,85],{"class":81}," default",[75,87,89],{"class":88},"sGLFI"," defineNuxtConfig",[75,91,93],{"class":92},"su5hD","(",[75,95,97],{"class":96},"sP7_E","{\n",[75,99,101,105,108,111,115,119,121,124],{"class":77,"line":100},2,[75,102,104],{"class":103},"skxfh","  modules",[75,106,107],{"class":96},":",[75,109,110],{"class":92}," [",[75,112,114],{"class":113},"sjJ54","'",[75,116,118],{"class":117},"s_sjI","@kurashina-design\u002Fnuxt-bff-guard",[75,120,114],{"class":113},[75,122,123],{"class":92},"]",[75,125,126],{"class":96},",\n",[75,128,130,133,135],{"class":77,"line":129},3,[75,131,132],{"class":103},"  bffGuard",[75,134,107],{"class":96},[75,136,137],{"class":96}," {\n",[75,139,141],{"class":77,"line":140},4,[75,142,144],{"class":143},"sutJx","    \u002F\u002F 'user' stays the default: every route needs a verified user unless it says otherwise.\n",[75,146,148,151,153,156,159,161],{"class":77,"line":147},5,[75,149,150],{"class":103},"    verifyUser",[75,152,107],{"class":96},[75,154,155],{"class":113}," '",[75,157,158],{"class":117},".\u002Fserver\u002Fauth\u002Fverify-user.ts",[75,160,114],{"class":113},[75,162,126],{"class":96},[75,164,166],{"class":77,"line":165},6,[75,167,168],{"class":96},"  },\n",[75,170,172,175],{"class":77,"line":171},7,[75,173,174],{"class":96},"}",[75,176,177],{"class":92},")\n",[65,179,182],{"className":67,"code":180,"filename":181,"language":70,"meta":71,"style":71},"import { defineBffHandler } from '#bff-guard'\n\n\u002F\u002F No account yet, but only your own pages may send it.\nexport default defineBffHandler(async (event) => {\n  await createLead(await readValidatedBody(event, leadSchema))\n  return { ok: true }\n}, { access: 'visitor' })\n","server\u002Fapi\u002Fdemo-request.post.ts",[61,183,184,209,215,220,249,278,297],{"__ignoreMap":71},[75,185,186,189,192,195,198,201,203,206],{"class":77,"line":78},[75,187,188],{"class":81},"import",[75,190,191],{"class":96}," {",[75,193,194],{"class":92}," defineBffHandler",[75,196,197],{"class":96}," }",[75,199,200],{"class":81}," from",[75,202,155],{"class":113},[75,204,205],{"class":117},"#bff-guard",[75,207,208],{"class":113},"'\n",[75,210,211],{"class":77,"line":100},[75,212,214],{"emptyLinePlaceholder":213},true,"\n",[75,216,217],{"class":77,"line":129},[75,218,219],{"class":143},"\u002F\u002F No account yet, but only your own pages may send it.\n",[75,221,222,224,226,228,230,234,237,241,244,247],{"class":77,"line":140},[75,223,82],{"class":81},[75,225,85],{"class":81},[75,227,194],{"class":88},[75,229,93],{"class":92},[75,231,233],{"class":232},"sbsja","async",[75,235,236],{"class":96}," (",[75,238,240],{"class":239},"s99_P","event",[75,242,243],{"class":96},")",[75,245,246],{"class":232}," =>",[75,248,137],{"class":96},[75,250,251,254,257,259,262,265,267,269,272,275],{"class":77,"line":147},[75,252,253],{"class":81},"  await",[75,255,256],{"class":88}," createLead",[75,258,93],{"class":103},[75,260,261],{"class":81},"await",[75,263,264],{"class":88}," readValidatedBody",[75,266,93],{"class":103},[75,268,240],{"class":92},[75,270,271],{"class":96},",",[75,273,274],{"class":92}," leadSchema",[75,276,277],{"class":103},"))\n",[75,279,280,283,285,288,290,294],{"class":77,"line":165},[75,281,282],{"class":81},"  return",[75,284,191],{"class":96},[75,286,287],{"class":103}," ok",[75,289,107],{"class":96},[75,291,293],{"class":292},"syTEX"," true",[75,295,296],{"class":96}," }\n",[75,298,299,302,304,307,309,311,314,316,318],{"class":77,"line":171},[75,300,301],{"class":96},"},",[75,303,191],{"class":96},[75,305,306],{"class":103}," access",[75,308,107],{"class":96},[75,310,155],{"class":113},[75,312,313],{"class":117},"visitor",[75,315,114],{"class":113},[75,317,197],{"class":96},[75,319,177],{"class":92},[65,321,324],{"className":67,"code":322,"filename":323,"language":70,"meta":71,"style":71},"import { defineBffHandler } from '#bff-guard'\n\n\u002F\u002F Rendered into the pricing page during SSR: public.\nexport default defineBffHandler(() => getPriceTable(), { access: 'public' })\n","server\u002Fapi\u002Fpricing.get.ts",[61,325,326,344,348,353],{"__ignoreMap":71},[75,327,328,330,332,334,336,338,340,342],{"class":77,"line":78},[75,329,188],{"class":81},[75,331,191],{"class":96},[75,333,194],{"class":92},[75,335,197],{"class":96},[75,337,200],{"class":81},[75,339,155],{"class":113},[75,341,205],{"class":117},[75,343,208],{"class":113},[75,345,346],{"class":77,"line":100},[75,347,214],{"emptyLinePlaceholder":213},[75,349,350],{"class":77,"line":129},[75,351,352],{"class":143},"\u002F\u002F Rendered into the pricing page during SSR: public.\n",[75,354,355,357,359,361,363,366,368,371,373,375,377,379,381,383,386,388,390],{"class":77,"line":140},[75,356,82],{"class":81},[75,358,85],{"class":81},[75,360,194],{"class":88},[75,362,93],{"class":92},[75,364,365],{"class":96},"()",[75,367,246],{"class":232},[75,369,370],{"class":88}," getPriceTable",[75,372,365],{"class":92},[75,374,271],{"class":96},[75,376,191],{"class":96},[75,378,306],{"class":103},[75,380,107],{"class":96},[75,382,155],{"class":113},[75,384,385],{"class":117},"public",[75,387,114],{"class":113},[75,389,197],{"class":96},[75,391,177],{"class":92},[65,393,396],{"className":67,"code":394,"filename":395,"language":70,"meta":71,"style":71},"import { defineBffHandler } from '#bff-guard'\n\n\u002F\u002F The default: verifyUser must accept the request.\nexport default defineBffHandler(event => listInvoices(event.context.user!.id))\n","server\u002Fapi\u002Finvoices.get.ts",[61,397,398,416,420,425],{"__ignoreMap":71},[75,399,400,402,404,406,408,410,412,414],{"class":77,"line":78},[75,401,188],{"class":81},[75,403,191],{"class":96},[75,405,194],{"class":92},[75,407,197],{"class":96},[75,409,200],{"class":81},[75,411,155],{"class":113},[75,413,205],{"class":117},[75,415,208],{"class":113},[75,417,418],{"class":77,"line":100},[75,419,214],{"emptyLinePlaceholder":213},[75,421,422],{"class":77,"line":129},[75,423,424],{"class":143},"\u002F\u002F The default: verifyUser must accept the request.\n",[75,426,427,429,431,433,435,437,439,442,445,448,451,453,456,460,462],{"class":77,"line":140},[75,428,82],{"class":81},[75,430,85],{"class":81},[75,432,194],{"class":88},[75,434,93],{"class":92},[75,436,240],{"class":239},[75,438,246],{"class":232},[75,440,441],{"class":88}," listInvoices",[75,443,444],{"class":92},"(event",[75,446,447],{"class":96},".",[75,449,450],{"class":92},"context",[75,452,447],{"class":96},[75,454,455],{"class":92},"user",[75,457,459],{"class":458},"smGrS","!",[75,461,447],{"class":96},[75,463,464],{"class":92},"id))\n",[57,466,467,468,471,472,474],{},"Reviewers see the exception on the route that makes it. A new route without an ",[61,469,470],{},"access"," option is protected by ",[61,473,14],{},", so forgetting the option fails closed.",[476,477,478],"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 .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--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 .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}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);}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .syTEX, html code.shiki .syTEX{--shiki-light:#FF5370;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":71,"searchDepth":100,"depth":100,"links":480},[],"Keep 'user' as the default and open a few routes to visitors without accounts.","md",{},"\u002Fexamples\u002Fmember-site-contact",{"title":52,"description":481},"examples\u002Fmember-site-contact",[488,14],"access: 'visitor'","Qp8ibf-ZJOG_32PD8xNH14T1UXtEvL1sLRpYJORsD80",[491,495],{"path":492,"title":493,"description":494,"category":313,"order":129},"\u002Fexamples\u002Fclient-data","JSON for client-side pages","Data that your pages fetch in the browser, kept from being embedded by other sites.",{"path":496,"title":497,"description":498,"category":499,"order":78},"\u002Fexamples\u002Fnuxt-auth-utils","nuxt-auth-utils","Use the sealed Cookie session of nuxt-auth-utils as the user check.","auth",[501,508,515,519,521,524,532,540,547,555,563,570,578,585,591,598,606,612,620,626,634,640,646,652,660],{"path":502,"title":503,"description":504,"category":313,"order":78,"uses":505},"\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.",[488,506,507],"@nuxtjs\u002Fturnstile","nuxt-security",{"path":509,"title":510,"description":511,"category":313,"order":100,"uses":512},"\u002Fexamples\u002Fpaid-api-proxy","Search box that calls a paid API","Keep other sites and scripts from spending your API quota through your BFF.",[488,513,514],"rateLimiter","defineCachedFunction",{"path":492,"title":493,"description":494,"category":313,"order":129,"uses":516},[488,517,518],"access: 'public'","useFetch",{"path":484,"title":52,"description":481,"category":313,"order":140,"uses":520},[488,14],{"path":496,"title":497,"description":498,"category":499,"order":78,"uses":522},[497,523],"requireUserSession",{"path":525,"title":526,"description":527,"category":499,"order":100,"uses":528},"\u002Fexamples\u002Fsidebase-nuxt-auth","Auth.js with @sidebase\u002Fnuxt-auth","Check the Auth.js session, and accept the same JWT as a Bearer token.",[529,530,531],"@sidebase\u002Fnuxt-auth","getServerSession","getToken",{"path":533,"title":534,"description":535,"category":499,"order":129,"uses":536},"\u002Fexamples\u002Fsupabase","Supabase","Verify the Supabase session with getClaims, and tell bad tokens from outages.",[537,538,539],"@nuxtjs\u002Fsupabase","getClaims","isAuthRetryableFetchError",{"path":541,"title":542,"description":543,"category":499,"order":140,"uses":544},"\u002Fexamples\u002Fclerk","Clerk","Read the auth object that Clerk's middleware put on the event.",[545,546],"@clerk\u002Fnuxt","event.context.auth",{"path":548,"title":549,"description":550,"category":499,"order":147,"uses":551},"\u002Fexamples\u002Ffirebase","Firebase Authentication","Session Cookies for the browser, ID tokens for apps, and error codes mapped to 401 or 503.",[552,553,554],"firebase-admin","verifySessionCookie","verifyIdToken",{"path":556,"title":557,"description":558,"category":499,"order":165,"uses":559},"\u002Fexamples\u002Fjwt-jose","Any OpenID Connect provider (JWT)","Verify access tokens from Auth0, Keycloak, Cognito, Entra ID and others with jose.",[560,561,562],"jose","jwtVerify","createRemoteJWKSet",{"path":564,"title":565,"description":566,"category":567,"order":78,"uses":568},"\u002Fexamples\u002Fnuxt-security-rate-limit","Rate limits with nuxt-security","Slow down credential stuffing and token guessing before verifyUser runs.","security",[507,513,569],"routeRules",{"path":571,"title":572,"description":573,"category":567,"order":100,"uses":574},"\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.",[507,575,576,577],"headers","requestSizeLimiter","allowedMethodsRestricter",{"path":579,"title":580,"description":581,"category":567,"order":129,"uses":582},"\u002Fexamples\u002Fnuxt-csurf","CSRF tokens with nuxt-csurf","Add a synchronizer token on top of the origin check, without breaking Bearer clients.",[583,584,569],"nuxt-csurf","useCsrfFetch",{"path":586,"title":587,"description":588,"category":567,"order":140,"uses":589},"\u002Fexamples\u002Fturnstile","Bot checks on public routes with Turnstile","Public sign-in and sign-up routes skip verifyUser, so give them their own check.",[506,590],"verifyTurnstileToken",{"path":592,"title":593,"description":594,"category":567,"order":147,"uses":595},"\u002Fexamples\u002Fcors-bearer-clients","A frontend on another origin","CORS with nuxt-security for a separate app that calls the BFF with Bearer tokens.",[507,596,597],"corsHandler","viaBearer",{"path":599,"title":600,"description":601,"category":602,"order":78,"uses":603},"\u002Fexamples\u002Frecord-authorization","Per-record authorization","The guard says who the user is. The handler decides what they may touch.","patterns",[604,605],"event.context","createError",{"path":607,"title":608,"description":609,"category":602,"order":100,"uses":610},"\u002Fexamples\u002Froles","Roles and app-wide access","Reject whole groups of users in verifyUser, and check roles per route.",[14,611],"403",{"path":613,"title":614,"description":615,"category":602,"order":129,"uses":616},"\u002Fexamples\u002Fupstream-proxy","Calling an upstream API","Attach the user's token after the guard, never in middleware or routeRules.proxy.",[617,618,619],"$fetch","routeRules.proxy","server\u002Futils",{"path":621,"title":622,"description":623,"category":602,"order":140,"uses":624},"\u002Fexamples\u002Fssr-and-server-functions","SSR and server functions","Call your own API during server rendering, or skip HTTP entirely.",[518,625,619],"useRequestFetch",{"path":627,"title":628,"description":629,"category":602,"order":147,"uses":630},"\u002Fexamples\u002Fwebhooks","Webhooks","Server-to-server callbacks belong outside server\u002Fapi, with their own signature check.",[631,632,633],"server\u002Froutes","readRawBody","xssValidator",{"path":635,"title":636,"description":637,"category":602,"order":165,"uses":638},"\u002Fexamples\u002Fbearer-clients","Mobile apps and CLI tools","One BFF for the browser and for clients that send Bearer tokens.",[597,639],"Authorization",{"path":641,"title":642,"description":643,"category":602,"order":171,"uses":644},"\u002Fexamples\u002Fmore-route-folders","Checking more folders at build time","Extend routePatterns to server\u002Froutes and layers.",[645],"routePatterns",{"path":647,"title":648,"description":649,"category":602,"order":650,"uses":651},"\u002Fexamples\u002Fpublic-cache","Caching public data","Cache what is the same for everyone on a separate public route.",8,[514,517],{"path":653,"title":654,"description":655,"category":602,"order":656,"uses":657},"\u002Fexamples\u002Fclient-errors","Handling 401, 403 and 503 in the app","Sign out on 401, explain 403, retry on 503.",9,[658,659],"$fetch.create","onResponseError",{"path":661,"title":662,"description":663,"category":602,"order":664,"uses":665},"\u002Fexamples\u002Ftesting","Testing the protection","An end-to-end test that every protected route refuses anonymous calls.",10,[666,667],"@nuxt\u002Ftest-utils","vitest",1796451483527,"a99f93bd-e267-45a7-90df-9194cd77468d"]