[{"data":1,"prerenderedAt":364},["ShallowReactive",2],{"navigation_docs":3,"-core-concepts-server-auth":152,"-core-concepts-server-auth-surround":359},[4,42,68,110,131],{"title":5,"path":6,"stem":7,"children":8,"icon":11},"Getting Started","/getting-started","1.getting-started/0.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","/getting-started/installation","1.getting-started/1.installation","i-lucide-download",{"title":18,"path":19,"stem":20,"icon":21},"Configuration","/getting-started/configuration","1.getting-started/2.configuration","i-lucide-settings",{"title":23,"path":24,"stem":25,"icon":26},"Client Setup","/getting-started/client-setup","1.getting-started/3.client-setup","i-lucide-monitor",{"title":28,"path":29,"stem":30,"icon":31},"Type Augmentation","/getting-started/type-augmentation","1.getting-started/4.type-augmentation","i-lucide-type",{"title":33,"path":34,"stem":35,"icon":36},"Schema Generation (NuxtHub)","/getting-started/schema-generation","1.getting-started/5.schema-generation","i-lucide-database",{"title":38,"path":39,"stem":40,"icon":41},"How It Works","/getting-started/how-it-works","1.getting-started/6.how-it-works","i-lucide-workflow",{"title":43,"path":44,"stem":45,"children":46,"page":67},"Core Concepts","/core-concepts","2.core-concepts",[47,51,55,59,63],{"title":48,"path":49,"stem":50},"serverAuth()","/core-concepts/server-auth","2.core-concepts/1.server-auth",{"title":52,"path":53,"stem":54},"Sessions","/core-concepts/sessions","2.core-concepts/2.sessions",{"title":56,"path":57,"stem":58},"Route Protection","/core-concepts/route-protection","2.core-concepts/3.route-protection",{"title":60,"path":61,"stem":62},"Auto‑Imports and Aliases","/core-concepts/auto-imports-aliases","2.core-concepts/4.auto-imports-aliases",{"title":64,"path":65,"stem":66},"Security & Caveats","/core-concepts/security-caveats","2.core-concepts/5.security-caveats",false,{"title":69,"path":70,"stem":71,"children":72,"page":67},"Guides","/guides","3.guides",[73,77,81,85,89,94,98,102,106],{"title":74,"path":75,"stem":76},"Role‑Based Access","/guides/role-based-access","3.guides/1.role-based-access",{"title":78,"path":79,"stem":80},"OAuth Providers","/guides/oauth-providers","3.guides/2.oauth-providers",{"title":82,"path":83,"stem":84},"Custom Database","/guides/custom-database","3.guides/3.custom-database",{"title":86,"path":87,"stem":88},"Database-less Mode","/guides/database-less-mode","3.guides/4.database-less-mode",{"title":90,"path":91,"stem":92,"icon":93},"External Auth Backend","/guides/external-auth-backend","3.guides/5.external-auth-backend","i-lucide-server",{"title":95,"path":96,"stem":97},"Migrating from nuxt-auth-utils","/guides/migrate-from-nuxt-auth-utils","3.guides/6.migrate-from-nuxt-auth-utils",{"title":99,"path":100,"stem":101},"Two-Factor Authentication (TOTP + Backup Codes)","/guides/two-factor-auth","3.guides/7.two-factor-auth",{"title":103,"path":104,"stem":105},"Testing","/guides/testing","3.guides/8.testing",{"title":107,"path":108,"stem":109},"Production Deployment","/guides/production-deployment","3.guides/9.production-deployment",{"title":111,"path":112,"stem":113,"children":114,"page":67},"Integrations","/integrations","4.integrations",[115,119,123,127],{"title":116,"path":117,"stem":118},"NuxtHub","/integrations/nuxthub","4.integrations/1.nuxthub",{"title":120,"path":121,"stem":122},"DevTools","/integrations/devtools","4.integrations/2.devtools",{"title":124,"path":125,"stem":126},"Convex","/integrations/convex","4.integrations/3.convex",{"title":128,"path":129,"stem":130},"i18n","/integrations/i18n","4.integrations/4.i18n",{"title":132,"path":133,"stem":134,"children":135,"page":67},"API Reference","/api","5.api",[136,140,144,148],{"title":137,"path":138,"stem":139},"Composables","/api/composables","5.api/1.composables",{"title":141,"path":142,"stem":143},"Server Utilities","/api/server-utils","5.api/2.server-utils",{"title":145,"path":146,"stem":147},"Components","/api/components","5.api/3.components",{"title":149,"path":150,"stem":151},"Types","/api/types","5.api/4.types",{"id":153,"title":48,"body":154,"description":353,"extension":354,"links":355,"meta":356,"navigation":184,"path":49,"seo":357,"stem":50,"__hash__":358},"docs/2.core-concepts/1.server-auth.md",{"type":155,"value":156,"toc":350},"minimark",[157,233,247,252,343,346],[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 @onmax/nuxt-better-auth.\n\n- `serverAuth(event?)` — returns the Better Auth instance. Pass `event` in Nitro handlers for request-aware base URLs\n- `getUserSession(event)` — get current session (auto-imported in `server/`)\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- All server utils are auto-imported, no import statements needed\n\nRead more: https://better-auth.nuxt.dev/raw/core-concepts/server-auth.md\nSource: https://github.com/nuxt-modules/better-auth\n","Prompt","txt","",[169,170,171,179,186,192,198,204,210,216,221,227],"code",{"__ignoreMap":167},[172,173,176],"span",{"class":174,"line":175},"line",1,[172,177,178],{},"Use server-side auth utilities in @onmax/nuxt-better-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-aware base URLs\n",[172,193,195],{"class":174,"line":194},4,[172,196,197],{},"- `getUserSession(event)` — get current session (auto-imported in `server/`)\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],{},"- All server utils are auto-imported, no import statements needed\n",[172,217,219],{"class":174,"line":218},8,[172,220,185],{"emptyLinePlaceholder":184},[172,222,224],{"class":174,"line":223},9,[172,225,226],{},"Read more: https://better-auth.nuxt.dev/raw/core-concepts/server-auth.md\n",[172,228,230],{"class":174,"line":229},10,[172,231,232],{},"Source: https://github.com/nuxt-modules/better-auth\n",[234,235,236,239,240,243,244,246],"p",{},[169,237,238],{},"serverAuth(event?)"," returns the Better Auth instance (module-level singleton). In Nitro handlers, you should pass ",[169,241,242],{},"event"," so the module can resolve request-aware base URLs on initialization. Outside request contexts (seed scripts, tasks, plugins), you can call ",[169,245,48],{}," without an event.",[248,249,251],"h2",{"id":250},"when-to-use-what","When to Use What",[253,254,255,271],"table",{},[256,257,258],"thead",{},[259,260,261,265,268],"tr",{},[262,263,264],"th",{},"Task",[262,266,267],{},"Use",[262,269,270],{},"Example",[272,273,274,288,301,314,330],"tbody",{},[259,275,276,280,285],{},[277,278,279],"td",{},"Get request-cached session context",[277,281,282],{},[169,283,284],{},"getRequestSession(event)",[277,286,287],{},"Cache once per request with context-backed storage when available",[259,289,290,293,298],{},[277,291,292],{},"Get current session",[277,294,295],{},[169,296,297],{},"getUserSession(event)",[277,299,300],{},"Check if user is logged in",[259,302,303,306,311],{},[277,304,305],{},"Require authentication",[277,307,308],{},[169,309,310],{},"requireUserSession(event)",[277,312,313],{},"Protect an API route",[259,315,316,319,324],{},[277,317,318],{},"Access Better Auth API",[277,320,321],{},[169,322,323],{},"serverAuth(event)",[277,325,326,327],{},"Call ",[169,328,329],{},"auth.api.listSessions()",[259,331,332,335,340],{},[277,333,334],{},"Get session with options",[277,336,337],{},[169,338,339],{},"requireUserSession(event, { user: { role: 'admin' } })",[277,341,342],{},"Role-based protection",[344,345],"read-more",{"to":142},[347,348,349],"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":351},[352],{"id":250,"depth":181,"text":251},"When to reach for the full Better Auth server instance.","md",null,{},{"title":48,"description":353},"Z-haTxoBwM4eRaUMqRbPKDz0DZc7YfHIqgE7tjyW4YI",[360,362],{"title":38,"path":39,"stem":40,"description":361,"icon":41,"children":-1},"Understand the architecture after completing setup.",{"title":52,"path":53,"stem":54,"description":363,"children":-1},"Access reactive session state with SSR support using `useUserSession()`.",1774627856054]