[{"data":1,"prerenderedAt":716,"buildId":717},["ShallowReactive",2],{"docs-navigation-en":3,"examples-en":50,"page-\u002Fdocs\u002Froute-coverage":237,"surround-\u002Fdocs\u002Froute-coverage":711},[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":22,"body":239,"description":706,"extension":707,"meta":708,"navigation":377,"path":23,"seo":709,"stem":24,"__hash__":710},"docs_en\u002Fdocs\u002F04.route-coverage.md",{"type":240,"value":241,"toc":701},"minimark",[242,250,271,274,315,320,555,558,562,573,640,655,659,691,697],[243,244,245,246,249],"p",{},"When Nitro starts a build, the module reads every route file matched by ",[247,248,214],"code",{}," and parses it with the TypeScript compiler. Each file must:",[251,252,253,265],"ol",{},[254,255,256,257,260,261,264],"li",{},"import ",[247,258,259],{},"defineBffHandler"," from ",[247,262,263],{},"#bff-guard"," (a renamed import is fine), and",[254,266,267,270],{},[247,268,269],{},"export default"," a direct call of it.",[243,272,273],{},"Otherwise the build fails:",[275,276,281],"pre",{"className":277,"code":278,"language":279,"meta":280,"style":280},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","[bffGuard] Route coverage check failed. Import defineBffHandler from #bff-guard and call it in the default export:\n  - server\u002Fapi\u002Fforgotten.get.ts\n","bash","",[247,282,283,305],{"__ignoreMap":280},[284,285,287,291,295,298,301],"span",{"class":286,"line":56},"line",[284,288,290],{"class":289},"sP7_E","[",[284,292,294],{"class":293},"su5hD","bffGuard",[284,296,297],{"class":289},"]",[284,299,300],{"class":293}," Route coverage check failed. Import defineBffHandler from ",[284,302,304],{"class":303},"sutJx","#bff-guard and call it in the default export:\n",[284,306,307,311],{"class":286,"line":65},[284,308,310],{"class":309},"sbgvK","  -",[284,312,314],{"class":313},"s_sjI"," server\u002Fapi\u002Fforgotten.get.ts\n",[316,317,319],"h2",{"id":318},"accepted-and-rejected","Accepted and rejected",[275,321,325],{"className":322,"code":323,"language":324,"meta":280,"style":280},"language-ts shiki shiki-themes material-theme-lighter github-light github-dark","\u002F\u002F ✅ accepted\nimport { defineBffHandler } from '#bff-guard'\nexport default defineBffHandler(handler)\n\n\u002F\u002F ✅ accepted: renamed import\nimport { defineBffHandler as guard } from '#bff-guard'\nexport default guard(handler, { access: 'public' })\n\n\u002F\u002F ❌ rejected: re-export from another file\nexport { default } from '.\u002Forders'\n\n\u002F\u002F ❌ rejected: wrapper or variable in between\nconst handler = defineBffHandler(listOrders)\nexport default handler\n\n\u002F\u002F ❌ rejected: a function with the same name from somewhere else\nimport { defineBffHandler } from '~\u002Fserver\u002Futils\u002Fguard'\nexport default defineBffHandler(handler)\n","ts",[247,326,327,332,359,373,379,384,408,444,448,453,472,477,483,503,513,518,524,544],{"__ignoreMap":280},[284,328,329],{"class":286,"line":56},[284,330,331],{"class":303},"\u002F\u002F ✅ accepted\n",[284,333,334,338,341,344,347,350,354,356],{"class":286,"line":65},[284,335,337],{"class":336},"sVHd0","import",[284,339,340],{"class":289}," {",[284,342,343],{"class":293}," defineBffHandler",[284,345,346],{"class":289}," }",[284,348,349],{"class":336}," from",[284,351,353],{"class":352},"sjJ54"," '",[284,355,263],{"class":313},[284,357,358],{"class":352},"'\n",[284,360,361,364,367,370],{"class":286,"line":73},[284,362,363],{"class":336},"export",[284,365,366],{"class":336}," default",[284,368,343],{"class":369},"sGLFI",[284,371,372],{"class":293},"(handler)\n",[284,374,375],{"class":286,"line":81},[284,376,378],{"emptyLinePlaceholder":377},true,"\n",[284,380,381],{"class":286,"line":117},[284,382,383],{"class":303},"\u002F\u002F ✅ accepted: renamed import\n",[284,385,386,388,390,392,395,398,400,402,404,406],{"class":286,"line":126},[284,387,337],{"class":336},[284,389,340],{"class":289},[284,391,343],{"class":293},[284,393,394],{"class":336}," as",[284,396,397],{"class":293}," guard",[284,399,346],{"class":289},[284,401,349],{"class":336},[284,403,353],{"class":352},[284,405,263],{"class":313},[284,407,358],{"class":352},[284,409,410,412,414,416,419,422,424,428,431,433,436,439,441],{"class":286,"line":212},[284,411,363],{"class":336},[284,413,366],{"class":336},[284,415,397],{"class":369},[284,417,418],{"class":293},"(handler",[284,420,421],{"class":289},",",[284,423,340],{"class":289},[284,425,427],{"class":426},"skxfh"," access",[284,429,430],{"class":289},":",[284,432,353],{"class":352},[284,434,435],{"class":313},"public",[284,437,438],{"class":352},"'",[284,440,346],{"class":289},[284,442,443],{"class":293},")\n",[284,445,446],{"class":286,"line":219},[284,447,378],{"emptyLinePlaceholder":377},[284,449,450],{"class":286,"line":225},[284,451,452],{"class":303},"\u002F\u002F ❌ rejected: re-export from another file\n",[284,454,455,457,459,461,463,465,467,470],{"class":286,"line":233},[284,456,363],{"class":336},[284,458,340],{"class":289},[284,460,366],{"class":336},[284,462,346],{"class":289},[284,464,349],{"class":336},[284,466,353],{"class":352},[284,468,469],{"class":313},".\u002Forders",[284,471,358],{"class":352},[284,473,475],{"class":286,"line":474},11,[284,476,378],{"emptyLinePlaceholder":377},[284,478,480],{"class":286,"line":479},12,[284,481,482],{"class":303},"\u002F\u002F ❌ rejected: wrapper or variable in between\n",[284,484,486,490,494,498,500],{"class":286,"line":485},13,[284,487,489],{"class":488},"sbsja","const",[284,491,493],{"class":492},"s_hVV"," handler",[284,495,497],{"class":496},"smGrS"," =",[284,499,343],{"class":369},[284,501,502],{"class":293},"(listOrders)\n",[284,504,506,508,510],{"class":286,"line":505},14,[284,507,363],{"class":336},[284,509,366],{"class":336},[284,511,512],{"class":293}," handler\n",[284,514,516],{"class":286,"line":515},15,[284,517,378],{"emptyLinePlaceholder":377},[284,519,521],{"class":286,"line":520},16,[284,522,523],{"class":303},"\u002F\u002F ❌ rejected: a function with the same name from somewhere else\n",[284,525,527,529,531,533,535,537,539,542],{"class":286,"line":526},17,[284,528,337],{"class":336},[284,530,340],{"class":289},[284,532,343],{"class":293},[284,534,346],{"class":289},[284,536,349],{"class":336},[284,538,353],{"class":352},[284,540,541],{"class":313},"~\u002Fserver\u002Futils\u002Fguard",[284,543,358],{"class":352},[284,545,547,549,551,553],{"class":286,"line":546},18,[284,548,363],{"class":336},[284,550,366],{"class":336},[284,552,343],{"class":369},[284,554,372],{"class":293},[243,556,557],{},"The rule is strict on purpose: a reviewer can see the protection on the route file itself.",[316,559,561],{"id":560},"choosing-the-patterns","Choosing the patterns",[243,563,564,565,568,569,572],{},"The default is ",[247,566,567],{},"['server\u002Fapi\u002F**']",", which follows Nitro's ",[247,570,571],{},"apiDir"," if you renamed it. To also check other folders, list them all. Your array replaces the default.",[275,574,577],{"className":322,"code":575,"filename":576,"language":324,"meta":280,"style":280},"bffGuard: {\n  verifyUser: '.\u002Fserver\u002Fauth\u002Fverify-user.ts',\n  routePatterns: ['server\u002Fapi\u002F**', 'server\u002Froutes\u002Fprivate\u002F**'],\n}\n","nuxt.config.ts",[247,578,579,588,605,635],{"__ignoreMap":280},[284,580,581,583,585],{"class":286,"line":56},[284,582,294],{"class":309},[284,584,430],{"class":289},[284,586,587],{"class":289}," {\n",[284,589,590,593,595,597,600,602],{"class":286,"line":65},[284,591,592],{"class":309},"  verifyUser",[284,594,430],{"class":289},[284,596,353],{"class":352},[284,598,599],{"class":313},".\u002Fserver\u002Fauth\u002Fverify-user.ts",[284,601,438],{"class":352},[284,603,604],{"class":289},",\n",[284,606,607,610,612,615,617,620,622,624,626,629,631,633],{"class":286,"line":73},[284,608,609],{"class":309},"  routePatterns",[284,611,430],{"class":289},[284,613,614],{"class":426}," [",[284,616,438],{"class":352},[284,618,619],{"class":313},"server\u002Fapi\u002F**",[284,621,438],{"class":352},[284,623,421],{"class":289},[284,625,353],{"class":352},[284,627,628],{"class":313},"server\u002Froutes\u002Fprivate\u002F**",[284,630,438],{"class":352},[284,632,297],{"class":426},[284,634,604],{"class":289},[284,636,637],{"class":286,"line":81},[284,638,639],{"class":289},"}\n",[243,641,642,643,646,647,650,651,654],{},"Each pattern starts with ",[247,644,645],{},"server\u002F"," and applies to every Nitro scan directory, including layers. Negative patterns (",[247,648,649],{},"!",") are not allowed. Keep helpers outside the checked folders, for example in ",[247,652,653],{},"server\u002Futils\u002F",".",[316,656,658],{"id":657},"what-the-check-cannot-see","What the check cannot see",[660,661,662,671,677,684],"ul",{},[254,663,664,665,668,669,654],{},"Handlers registered in ",[247,666,667],{},"nitro.handlers"," in ",[247,670,576],{},[254,672,673,674,654],{},"Handlers that other modules add with ",[247,675,676],{},"addServerHandler",[254,678,679,680,683],{},"Routes outside your patterns, such as ",[247,681,682],{},"server\u002Froutes\u002F**"," by default.",[254,685,686,687,690],{},"Routes added while ",[247,688,689],{},"nuxt dev"," is running. Restart, or rely on the production build.",[243,692,693,694,696],{},"Wrap such handlers in ",[247,695,259],{}," yourself and review them.",[698,699,700],"style",{},"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 .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 pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}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 .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 .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--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 .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--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":280,"searchDepth":65,"depth":65,"links":702},[703,704,705],{"id":318,"depth":65,"text":319},{"id":560,"depth":65,"text":561},{"id":657,"depth":65,"text":658},"How the build finds routes that forgot defineBffHandler.","md",{},{"title":22,"description":706},"nmT3gXffcrpynHbwuDx1KasW8c8nMJKrcOA2hB1b4Qw",[712,714],{"title":18,"path":19,"stem":20,"description":713,"children":-1},"Protect the BFF of a corporate site, a landing page or any app without sign-in.",{"title":26,"path":27,"stem":28,"description":715,"children":-1},"Health checks, sign-in entry points and other routes without a user.",1796451485241,"a99f93bd-e267-45a7-90df-9194cd77468d"]