[{"data":1,"prerenderedAt":480,"buildId":481},["ShallowReactive",2],{"-getting-started-how-it-works":3,"-getting-started-how-it-works-surround":263,"navigation_docs":275},{"id":4,"title":5,"body":6,"description":253,"extension":254,"links":255,"meta":256,"navigation":257,"path":259,"seo":260,"stem":261,"__hash__":262},"docs\u002F1.getting-started\u002F6.how-it-works.md","How It Works",{"type":7,"value":8,"toc":240},"minimark",[9,13,18,64,68,171,175,213,217],[10,11,12],"p",{},"Use this page after installation. It explains how the module connects Nuxt runtime behavior to Better Auth rather than walking through setup again.",[14,15,17],"h2",{"id":16},"architecture","Architecture",[19,20,21,26,39,43,53,57],"steps",{},[22,23,25],"h3",{"id":24},"initialization","Initialization",[10,27,28,29,33,34,38],{},"During build, the module reads ",[30,31,32],"code",{},"server\u002Fauth.config.ts"," and generates the auth handler. If using ",[35,36],"brand-badge",{"name":37},"nuxthub",", it also generates the database schema automatically.",[22,40,42],{"id":41},"server-runtime","Server Runtime",[10,44,45,46,49,50,52],{},"The module injects a catch-all API handler at ",[30,47,48],{},"\u002Fapi\u002Fauth\u002F**",". This handler processes all authentication requests (login, logout, session fetching) using the configuration provided in ",[30,51,32],{},".",[22,54,56],{"id":55},"client-runtime","Client Runtime",[10,58,59,60,63],{},"On the client side, ",[30,61,62],{},"useUserSession"," initializes the Better Auth client. It establishes a reactive connection to the session state, ensuring that your UI updates immediately when a user logs in or out.",[14,65,67],{"id":66},"key-responsibilities","Key Responsibilities",[69,70,71,87],"table",{},[72,73,74],"thead",{},[75,76,77,81,84],"tr",{},[78,79,80],"th",{},"Feature",[78,82,83],{},"What it provides",[78,85,86],{},"Side",[88,89,90,105,119,136,153],"tbody",{},[75,91,92,96,102],{},[93,94,95],"td",{},"Server handler",[93,97,98,99],{},"Mounts Better Auth at ",[30,100,101],{},"\u002Fapi\u002Fauth\u002F*",[93,103,104],{},"Server",[75,106,107,110,116],{},[93,108,109],{},"Composables",[93,111,112,115],{},[30,113,114],{},"useUserSession()"," for reactive state",[93,117,118],{},"Client",[75,120,121,124,134],{},[93,122,123],{},"Server utils",[93,125,126,129,130,133],{},[30,127,128],{},"serverAuth(event?)",", ",[30,131,132],{},"getUserSession(event)",", etc.",[93,135,104],{},[75,137,138,141,150],{},[93,139,140],{},"Route protection",[93,142,143,146,147],{},[30,144,145],{},"routeRules.auth"," and ",[30,148,149],{},"definePageMeta({ auth })",[93,151,152],{},"Both",[75,154,155,158,168],{},[93,156,157],{},"Type augmentation",[93,159,160,161,146,164,167],{},"Inferred ",[30,162,163],{},"AuthUser",[30,165,166],{},"AuthSession"," types",[93,169,170],{},"Build",[14,172,174],{"id":173},"request-flow","Request Flow",[176,177,178,182,193,196,202,205,208],"ol",{},[179,180,181],"li",{},"User visits a protected page",[179,183,184,185,188,189,192],{},"Route middleware checks ",[30,186,187],{},"auth"," rule in ",[30,190,191],{},"routeRules"," or page meta",[179,194,195],{},"If not authenticated, redirects to login page",[179,197,198,199],{},"User submits credentials to ",[30,200,201],{},"\u002Fapi\u002Fauth\u002Fsign-in\u002Femail",[179,203,204],{},"Better Auth validates credentials and creates session",[179,206,207],{},"Session cookie is set, user redirected to original page",[179,209,210,212],{},[30,211,114],{}," reads session from cookie, updates reactive state",[14,214,216],{"id":215},"what-this-means-in-practice","What this means in practice",[218,219,220,226,232,235],"ul",{},[179,221,222,223,225],{},"client pages use ",[30,224,114],{}," and related composables",[179,227,228,229],{},"protected API routes should still call ",[30,230,231],{},"requireUserSession(event)",[179,233,234],{},"route rules improve navigation UX, but server-side checks remain the real security boundary",[179,236,237,239],{},[35,238],{"name":37}," integration and schema generation are build-time concerns, not request-time concerns",{"title":241,"searchDepth":242,"depth":242,"links":243},"",2,[244,250,251,252],{"id":16,"depth":242,"text":17,"children":245},[246,248,249],{"id":24,"depth":247,"text":25},3,{"id":41,"depth":247,"text":42},{"id":55,"depth":247,"text":56},{"id":66,"depth":242,"text":67},{"id":173,"depth":242,"text":174},{"id":215,"depth":242,"text":216},"Understand the architecture after completing setup.","md",null,{},{"icon":258},"i-lucide-workflow","\u002Fgetting-started\u002Fhow-it-works",{"title":5,"description":253},"1.getting-started\u002F6.how-it-works","4pDwAR4dANKn7Dpbpxda5EKCVCZiUCOOeyLuH85liGk",[264,270],{"title":265,"path":266,"stem":267,"description":268,"icon":269,"children":-1},"Schema Generation (NuxtHub)","\u002Fgetting-started\u002Fschema-generation","1.getting-started\u002F5.schema-generation","Auto-generate Drizzle ORM schemas for Better Auth tables when using NuxtHub.","i-lucide-database",{"title":271,"path":272,"stem":273,"description":274,"children":-1},"serverAuth()","\u002Fcore-concepts\u002Fserver-auth","2.core-concepts\u002F1.server-auth","When to reach for the full Better Auth server instance.",[276,306,329,376,401,421],{"title":277,"path":278,"stem":279,"children":280,"icon":283},"Getting Started","\u002Fgetting-started","1.getting-started\u002F0.index",[281,284,289,294,299,304,305],{"title":282,"path":278,"stem":279,"icon":283},"Introduction","i-lucide-sparkles",{"title":285,"path":286,"stem":287,"icon":288},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F1.installation","i-lucide-download",{"title":290,"path":291,"stem":292,"icon":293},"Configuration","\u002Fgetting-started\u002Fconfiguration","1.getting-started\u002F2.configuration","i-lucide-settings",{"title":295,"path":296,"stem":297,"icon":298},"Client Setup","\u002Fgetting-started\u002Fclient-setup","1.getting-started\u002F3.client-setup","i-lucide-monitor",{"title":300,"path":301,"stem":302,"icon":303},"Type Augmentation","\u002Fgetting-started\u002Ftype-augmentation","1.getting-started\u002F4.type-augmentation","i-lucide-type",{"title":265,"path":266,"stem":267,"icon":269},{"title":5,"path":259,"stem":261,"icon":258},{"title":307,"path":308,"stem":309,"children":310,"page":328},"Core Concepts","\u002Fcore-concepts","2.core-concepts",[311,312,316,320,324],{"title":271,"path":272,"stem":273},{"title":313,"path":314,"stem":315},"Sessions","\u002Fcore-concepts\u002Fsessions","2.core-concepts\u002F2.sessions",{"title":317,"path":318,"stem":319},"Route Protection","\u002Fcore-concepts\u002Froute-protection","2.core-concepts\u002F3.route-protection",{"title":321,"path":322,"stem":323},"Auto‑Imports and Aliases","\u002Fcore-concepts\u002Fauto-imports-aliases","2.core-concepts\u002F4.auto-imports-aliases",{"title":325,"path":326,"stem":327},"Security & Caveats","\u002Fcore-concepts\u002Fsecurity-caveats","2.core-concepts\u002F5.security-caveats",false,{"title":330,"path":331,"stem":332,"children":333,"page":328},"Guides","\u002Fguides","3.guides",[334,338,343,347,351,355,360,364,368,372],{"title":335,"path":336,"stem":337},"Role‑Based Access","\u002Fguides\u002Frole-based-access","3.guides\u002F1.role-based-access",{"title":339,"path":340,"stem":341,"icon":342},"Setup diagnostics","\u002Fguides\u002Fdiagnostics","3.guides\u002F10.diagnostics","i-lucide-circle-alert",{"title":344,"path":345,"stem":346},"OAuth Providers","\u002Fguides\u002Foauth-providers","3.guides\u002F2.oauth-providers",{"title":348,"path":349,"stem":350},"Custom Database","\u002Fguides\u002Fcustom-database","3.guides\u002F3.custom-database",{"title":352,"path":353,"stem":354},"Database-less Mode","\u002Fguides\u002Fdatabase-less-mode","3.guides\u002F4.database-less-mode",{"title":356,"path":357,"stem":358,"icon":359},"External Auth Backend","\u002Fguides\u002Fexternal-auth-backend","3.guides\u002F5.external-auth-backend","i-lucide-server",{"title":361,"path":362,"stem":363},"Migrating from nuxt-auth-utils","\u002Fguides\u002Fmigrate-from-nuxt-auth-utils","3.guides\u002F6.migrate-from-nuxt-auth-utils",{"title":365,"path":366,"stem":367},"Two-Factor Authentication (TOTP + Backup Codes)","\u002Fguides\u002Ftwo-factor-auth","3.guides\u002F7.two-factor-auth",{"title":369,"path":370,"stem":371},"Testing","\u002Fguides\u002Ftesting","3.guides\u002F8.testing",{"title":373,"path":374,"stem":375},"Production Deployment","\u002Fguides\u002Fproduction-deployment","3.guides\u002F9.production-deployment",{"title":377,"path":378,"stem":379,"children":380,"page":328},"Integrations","\u002Fintegrations","4.integrations",[381,385,389,393,397],{"title":382,"path":383,"stem":384},"NuxtHub","\u002Fintegrations\u002Fnuxthub","4.integrations\u002F1.nuxthub",{"title":386,"path":387,"stem":388},"DevTools","\u002Fintegrations\u002Fdevtools","4.integrations\u002F2.devtools",{"title":390,"path":391,"stem":392},"Convex","\u002Fintegrations\u002Fconvex","4.integrations\u002F3.convex",{"title":394,"path":395,"stem":396},"i18n","\u002Fintegrations\u002Fi18n","4.integrations\u002F4.i18n",{"title":398,"path":399,"stem":400},"MCP","\u002Fintegrations\u002Fmcp","4.integrations\u002F5.mcp",{"title":402,"path":403,"stem":404,"children":405,"page":328},"API Reference","\u002Fapi","5.api",[406,409,413,417],{"title":109,"path":407,"stem":408},"\u002Fapi\u002Fcomposables","5.api\u002F1.composables",{"title":410,"path":411,"stem":412},"Server Utilities","\u002Fapi\u002Fserver-utils","5.api\u002F2.server-utils",{"title":414,"path":415,"stem":416},"Components","\u002Fapi\u002Fcomponents","5.api\u002F3.components",{"title":418,"path":419,"stem":420},"Types","\u002Fapi\u002Ftypes","5.api\u002F4.types",{"title":422,"path":423,"stem":424,"children":425,"icon":342},"Errors","\u002Ferrors","6.errors\u002F0.index",[426,428,432,436,440,444,448,452,456,460,464,468,472,476],{"title":427,"path":423,"stem":424},"Overview",{"title":429,"path":430,"stem":431},"Better Auth CLI is not installed","\u002Ferrors\u002Fnuxt-auth-cli-missing","6.errors\u002Fnuxt-auth-cli-missing",{"title":433,"path":434,"stem":435},"Better Auth CLI version does not match better-auth","\u002Ferrors\u002Fnuxt-auth-cli-version-mismatch","6.errors\u002Fnuxt-auth-cli-version-mismatch",{"title":437,"path":438,"stem":439},"Auth configuration failed to load","\u002Ferrors\u002Fnuxt-auth-config-load-failed","6.errors\u002Fnuxt-auth-config-load-failed",{"title":441,"path":442,"stem":443},"Schema generator returned no code","\u002Ferrors\u002Fnuxt-auth-empty-schema","6.errors\u002Fnuxt-auth-empty-schema",{"title":445,"path":446,"stem":447},"Invalid server auth config export","\u002Ferrors\u002Fnuxt-auth-invalid-config-export","6.errors\u002Fnuxt-auth-invalid-config-export",{"title":449,"path":450,"stem":451},"Auth plugin path must be absolute","\u002Ferrors\u002Fnuxt-auth-invalid-plugin-source","6.errors\u002Fnuxt-auth-invalid-plugin-source",{"title":453,"path":454,"stem":455},"Missing auth configuration","\u002Ferrors\u002Fnuxt-auth-missing-config","6.errors\u002Fnuxt-auth-missing-config",{"title":457,"path":458,"stem":459},"NuxtHub database alias is missing","\u002Ferrors\u002Fnuxt-auth-missing-hub-db","6.errors\u002Fnuxt-auth-missing-hub-db",{"title":461,"path":462,"stem":463},"No database provider is enabled","\u002Ferrors\u002Fnuxt-auth-no-database-provider","6.errors\u002Fnuxt-auth-no-database-provider",{"title":465,"path":466,"stem":467},"Auth schema generation failed","\u002Ferrors\u002Fnuxt-auth-schema-generation-failed","6.errors\u002Fnuxt-auth-schema-generation-failed",{"title":469,"path":470,"stem":471},"Custom session storage is missing","\u002Ferrors\u002Fnuxt-auth-schema-storage-required","6.errors\u002Fnuxt-auth-schema-storage-required",{"title":473,"path":474,"stem":475},"Secondary storage in client-only mode","\u002Ferrors\u002Fnuxt-auth-storage-client-only","6.errors\u002Fnuxt-auth-storage-client-only",{"title":477,"path":478,"stem":479},"Unsupported database dialect","\u002Ferrors\u002Fnuxt-auth-unsupported-dialect","6.errors\u002Fnuxt-auth-unsupported-dialect",1795841357972,"5b1c9a96-b882-49e9-89cc-8609b680bcab"]