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