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