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