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