[{"data":1,"prerenderedAt":441},["ShallowReactive",2],{"navigation_docs":3,"-core-concepts-server-auth":152,"-core-concepts-server-auth-surround":436},[4,42,68,110,131],{"title":5,"path":6,"stem":7,"children":8,"icon":11},"Getting Started","\u002Fgetting-started","1.getting-started\u002F0.index",[9,12,17,22,27,32,37],{"title":10,"path":6,"stem":7,"icon":11},"Introduction","i-lucide-sparkles",{"title":13,"path":14,"stem":15,"icon":16},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F1.installation","i-lucide-download",{"title":18,"path":19,"stem":20,"icon":21},"Configuration","\u002Fgetting-started\u002Fconfiguration","1.getting-started\u002F2.configuration","i-lucide-settings",{"title":23,"path":24,"stem":25,"icon":26},"Client Setup","\u002Fgetting-started\u002Fclient-setup","1.getting-started\u002F3.client-setup","i-lucide-monitor",{"title":28,"path":29,"stem":30,"icon":31},"Type Augmentation","\u002Fgetting-started\u002Ftype-augmentation","1.getting-started\u002F4.type-augmentation","i-lucide-type",{"title":33,"path":34,"stem":35,"icon":36},"Schema Generation (NuxtHub)","\u002Fgetting-started\u002Fschema-generation","1.getting-started\u002F5.schema-generation","i-lucide-database",{"title":38,"path":39,"stem":40,"icon":41},"How It Works","\u002Fgetting-started\u002Fhow-it-works","1.getting-started\u002F6.how-it-works","i-lucide-workflow",{"title":43,"path":44,"stem":45,"children":46,"page":67},"Core Concepts","\u002Fcore-concepts","2.core-concepts",[47,51,55,59,63],{"title":48,"path":49,"stem":50},"serverAuth()","\u002Fcore-concepts\u002Fserver-auth","2.core-concepts\u002F1.server-auth",{"title":52,"path":53,"stem":54},"Sessions","\u002Fcore-concepts\u002Fsessions","2.core-concepts\u002F2.sessions",{"title":56,"path":57,"stem":58},"Route Protection","\u002Fcore-concepts\u002Froute-protection","2.core-concepts\u002F3.route-protection",{"title":60,"path":61,"stem":62},"Auto‑Imports and Aliases","\u002Fcore-concepts\u002Fauto-imports-aliases","2.core-concepts\u002F4.auto-imports-aliases",{"title":64,"path":65,"stem":66},"Security & Caveats","\u002Fcore-concepts\u002Fsecurity-caveats","2.core-concepts\u002F5.security-caveats",false,{"title":69,"path":70,"stem":71,"children":72,"page":67},"Guides","\u002Fguides","3.guides",[73,77,81,85,89,94,98,102,106],{"title":74,"path":75,"stem":76},"Role‑Based Access","\u002Fguides\u002Frole-based-access","3.guides\u002F1.role-based-access",{"title":78,"path":79,"stem":80},"OAuth Providers","\u002Fguides\u002Foauth-providers","3.guides\u002F2.oauth-providers",{"title":82,"path":83,"stem":84},"Custom Database","\u002Fguides\u002Fcustom-database","3.guides\u002F3.custom-database",{"title":86,"path":87,"stem":88},"Database-less Mode","\u002Fguides\u002Fdatabase-less-mode","3.guides\u002F4.database-less-mode",{"title":90,"path":91,"stem":92,"icon":93},"External Auth Backend","\u002Fguides\u002Fexternal-auth-backend","3.guides\u002F5.external-auth-backend","i-lucide-server",{"title":95,"path":96,"stem":97},"Migrating from nuxt-auth-utils","\u002Fguides\u002Fmigrate-from-nuxt-auth-utils","3.guides\u002F6.migrate-from-nuxt-auth-utils",{"title":99,"path":100,"stem":101},"Two-Factor Authentication (TOTP + Backup Codes)","\u002Fguides\u002Ftwo-factor-auth","3.guides\u002F7.two-factor-auth",{"title":103,"path":104,"stem":105},"Testing","\u002Fguides\u002Ftesting","3.guides\u002F8.testing",{"title":107,"path":108,"stem":109},"Production Deployment","\u002Fguides\u002Fproduction-deployment","3.guides\u002F9.production-deployment",{"title":111,"path":112,"stem":113,"children":114,"page":67},"Integrations","\u002Fintegrations","4.integrations",[115,119,123,127],{"title":116,"path":117,"stem":118},"NuxtHub","\u002Fintegrations\u002Fnuxthub","4.integrations\u002F1.nuxthub",{"title":120,"path":121,"stem":122},"DevTools","\u002Fintegrations\u002Fdevtools","4.integrations\u002F2.devtools",{"title":124,"path":125,"stem":126},"Convex","\u002Fintegrations\u002Fconvex","4.integrations\u002F3.convex",{"title":128,"path":129,"stem":130},"i18n","\u002Fintegrations\u002Fi18n","4.integrations\u002F4.i18n",{"title":132,"path":133,"stem":134,"children":135,"page":67},"API Reference","\u002Fapi","5.api",[136,140,144,148],{"title":137,"path":138,"stem":139},"Composables","\u002Fapi\u002Fcomposables","5.api\u002F1.composables",{"title":141,"path":142,"stem":143},"Server Utilities","\u002Fapi\u002Fserver-utils","5.api\u002F2.server-utils",{"title":145,"path":146,"stem":147},"Components","\u002Fapi\u002Fcomponents","5.api\u002F3.components",{"title":149,"path":150,"stem":151},"Types","\u002Fapi\u002Ftypes","5.api\u002F4.types",{"id":153,"title":48,"body":154,"description":430,"extension":431,"links":432,"meta":433,"navigation":184,"path":49,"seo":434,"stem":50,"__hash__":435},"docs\u002F2.core-concepts\u002F1.server-auth.md",{"type":155,"value":156,"toc":426},"minimark",[157,228,232,253,258,375,380,383,387,408,422],[158,159,160],"code-collapse",{},[161,162,168],"pre",{"className":163,"code":164,"filename":165,"language":166,"meta":167,"style":167},"language-txt shiki shiki-themes one-light synthwave-84 synthwave-84","Use server-side auth utilities in @nuxtjs\u002Fbetter-auth.\n\n- `serverAuth(event?)` — returns the Better Auth instance. Pass `event` in Nitro handlers for request-scoped database access and configuration context\n- `getUserSession(event)` — get current session (auto-imported in `server\u002F`)\n- `requireUserSession(event, options?)` — throws 401 if not authenticated, supports role matching\n- `getRequestSession(event)` — request-cached session, preferred over repeated `getUserSession` in same request\n- `setRequestSession(event, session)` — supply an authenticated session to downstream helpers for the current request\n- `refreshSessionCookieCache(event)` — refresh Better Auth's cached session cookie after server-side session data changes\n- All server utils are auto-imported, no import statements needed\n","Prompt","txt","",[169,170,171,179,186,192,198,204,210,216,222],"code",{"__ignoreMap":167},[172,173,176],"span",{"class":174,"line":175},"line",1,[172,177,178],{},"Use server-side auth utilities in @nuxtjs\u002Fbetter-auth.\n",[172,180,182],{"class":174,"line":181},2,[172,183,185],{"emptyLinePlaceholder":184},true,"\n",[172,187,189],{"class":174,"line":188},3,[172,190,191],{},"- `serverAuth(event?)` — returns the Better Auth instance. Pass `event` in Nitro handlers for request-scoped database access and configuration context\n",[172,193,195],{"class":174,"line":194},4,[172,196,197],{},"- `getUserSession(event)` — get current session (auto-imported in `server\u002F`)\n",[172,199,201],{"class":174,"line":200},5,[172,202,203],{},"- `requireUserSession(event, options?)` — throws 401 if not authenticated, supports role matching\n",[172,205,207],{"class":174,"line":206},6,[172,208,209],{},"- `getRequestSession(event)` — request-cached session, preferred over repeated `getUserSession` in same request\n",[172,211,213],{"class":174,"line":212},7,[172,214,215],{},"- `setRequestSession(event, session)` — supply an authenticated session to downstream helpers for the current request\n",[172,217,219],{"class":174,"line":218},8,[172,220,221],{},"- `refreshSessionCookieCache(event)` — refresh Better Auth's cached session cookie after server-side session data changes\n",[172,223,225],{"class":174,"line":224},9,[172,226,227],{},"- All server utils are auto-imported, no import statements needed\n",[229,230,231],"p",{},"Use this page when you need authentication state or Better Auth APIs inside Nitro handlers, middleware, plugins, or other server-side code.",[229,233,234,237,238,241,242,245,246,249,250,252],{},[169,235,236],{},"serverAuth(event?)"," returns the Better Auth instance. Pass ",[169,239,240],{},"event"," in Nitro handlers for request-scoped database access and ",[169,243,244],{},"ctx.requestOrigin",". In production, the canonical auth URL comes from ",[169,247,248],{},"runtimeConfig.public.siteUrl"," or platform environment variables. Development can infer it from the request. Outside request contexts, such as seed scripts and tasks, call ",[169,251,48],{}," without an event.",[254,255,257],"h2",{"id":256},"when-to-use-what","When to Use What",[259,260,261,277],"table",{},[262,263,264],"thead",{},[265,266,267,271,274],"tr",{},[268,269,270],"th",{},"Task",[268,272,273],{},"Use",[268,275,276],{},"Example",[278,279,280,294,307,320,333,346,362],"tbody",{},[265,281,282,286,291],{},[283,284,285],"td",{},"Get request-cached session context",[283,287,288],{},[169,289,290],{},"getRequestSession(event)",[283,292,293],{},"Cache once per request with context-backed storage when available",[265,295,296,299,304],{},[283,297,298],{},"Supply a request session",[283,300,301],{},[169,302,303],{},"setRequestSession(event, session)",[283,305,306],{},"Reuse a session resolved by trusted server authentication",[265,308,309,312,317],{},[283,310,311],{},"Get current session",[283,313,314],{},[169,315,316],{},"getUserSession(event)",[283,318,319],{},"Check if user is logged in",[265,321,322,325,330],{},[283,323,324],{},"Refresh cached session cookie",[283,326,327],{},[169,328,329],{},"refreshSessionCookieCache(event)",[283,331,332],{},"Use after updating data returned by Better Auth session helpers",[265,334,335,338,343],{},[283,336,337],{},"Require authentication",[283,339,340],{},[169,341,342],{},"requireUserSession(event)",[283,344,345],{},"Protect an API route",[265,347,348,351,356],{},[283,349,350],{},"Access Better Auth API",[283,352,353],{},[169,354,355],{},"serverAuth(event)",[283,357,358,359],{},"Call ",[169,360,361],{},"auth.api.listSessions()",[265,363,364,367,372],{},[283,365,366],{},"Get session with options",[283,368,369],{},[169,370,371],{},"requireUserSession(event, { user: { role: 'admin' } })",[283,373,374],{},"Role-based protection",[229,376,377,379],{},[169,378,329],{}," refreshes the cached session cookie. It does not update the session or user record; perform that update first.",[381,382],"read-more",{"to":142},[254,384,386],{"id":385},"server-endpoint-path","Server endpoint path",[229,388,389,390,393,394,397,398,401,402,404,405,407],{},"The module registers Better Auth at ",[169,391,392],{},"\u002Fapi\u002Fauth",". ",[169,395,396],{},"defineServerAuth"," accepts only this ",[169,399,400],{},"basePath"," and rejects other values when resolving the config. Remove a custom server ",[169,403,400],{}," or set it to ",[169,406,392],{},"; update client URLs and OAuth callback URLs accordingly.",[229,409,410,411,414,415,417,418,421],{},"External backends configured with ",[169,412,413],{},"auth.clientOnly: true"," can still use a custom ",[169,416,400],{}," in ",[169,419,420],{},"defineClientAuth",".",[423,424,425],"style",{},"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":167,"searchDepth":181,"depth":181,"links":427},[428,429],{"id":256,"depth":181,"text":257},{"id":385,"depth":181,"text":386},"When to reach for the full Better Auth server instance.","md",null,{},{"title":48,"description":430},"B1pywlin_2aofvazRW1oP5G_KoziQPzUgUnS2WCvfh4",[437,439],{"title":38,"path":39,"stem":40,"description":438,"icon":41,"children":-1},"Understand the architecture after completing setup.",{"title":52,"path":53,"stem":54,"description":440,"children":-1},"Access reactive session state with SSR support using `useUserSession()`.",1788606330340]