[{"data":1,"prerenderedAt":1144},["ShallowReactive",2],{"navigation_docs":3,"-logging-better-auth-middleware":407,"-logging-better-auth-middleware-surround":1139},[4,35,159,201,289,304,391],{"title":5,"path":6,"stem":7,"children":8,"page":34},"Getting Started","\u002Fgetting-started","1.getting-started",[9,14,19,24,29],{"title":10,"path":11,"stem":12,"icon":13},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F1.introduction","i-lucide-info",{"title":15,"path":16,"stem":17,"icon":18},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F2.installation","i-lucide-download",{"title":20,"path":21,"stem":22,"icon":23},"Quick Start","\u002Fgetting-started\u002Fquick-start","1.getting-started\u002F3.quick-start","i-lucide-zap",{"title":25,"path":26,"stem":27,"icon":28},"Agent Skills","\u002Fgetting-started\u002Fagent-skills","1.getting-started\u002F4.agent-skills","i-lucide-sparkles",{"title":30,"path":31,"stem":32,"icon":33},"vs Other Loggers","\u002Fgetting-started\u002Fvs-other-loggers","1.getting-started\u002F5.vs-other-loggers","i-lucide-scale",false,{"title":36,"path":37,"stem":38,"children":39,"page":34},"Logging","\u002Flogging","2.logging",[40,45,50,55,60,65,70,99,127],{"title":41,"path":42,"stem":43,"icon":44},"Overview","\u002Flogging\u002Foverview","2.logging\u002F0.overview","i-lucide-list",{"title":46,"path":47,"stem":48,"icon":49},"Simple Logging","\u002Flogging\u002Fsimple-logging","2.logging\u002F1.simple-logging","i-lucide-terminal",{"title":51,"path":52,"stem":53,"icon":54},"Wide Events","\u002Flogging\u002Fwide-events","2.logging\u002F2.wide-events","i-lucide-layers",{"title":56,"path":57,"stem":58,"icon":59},"Structured Errors","\u002Flogging\u002Fstructured-errors","2.logging\u002F3.structured-errors","i-lucide-shield-alert",{"title":61,"path":62,"stem":63,"icon":64},"Catalogs","\u002Flogging\u002Fcatalogs","2.logging\u002F4.catalogs","i-lucide-book-open",{"title":66,"path":67,"stem":68,"icon":69},"Client Logging","\u002Flogging\u002Fclient-logging","2.logging\u002F5.client-logging","i-lucide-monitor",{"title":71,"icon":72,"path":73,"stem":74,"children":75,"page":34},"AI SDK","i-simple-icons-vercel","\u002Flogging\u002Fai-sdk","2.logging\u002F6.ai-sdk",[76,79,84,89,94],{"title":41,"path":77,"stem":78,"icon":44},"\u002Flogging\u002Fai-sdk\u002Foverview","2.logging\u002F6.ai-sdk\u002F01.overview",{"title":80,"path":81,"stem":82,"icon":83},"Usage","\u002Flogging\u002Fai-sdk\u002Fusage","2.logging\u002F6.ai-sdk\u002F02.usage","i-lucide-code",{"title":85,"path":86,"stem":87,"icon":88},"Options","\u002Flogging\u002Fai-sdk\u002Foptions","2.logging\u002F6.ai-sdk\u002F03.options","i-lucide-sliders",{"title":90,"path":91,"stem":92,"icon":93},"Metadata","\u002Flogging\u002Fai-sdk\u002Fmetadata","2.logging\u002F6.ai-sdk\u002F04.metadata","i-lucide-database",{"title":95,"path":96,"stem":97,"icon":98},"Telemetry","\u002Flogging\u002Fai-sdk\u002Ftelemetry","2.logging\u002F6.ai-sdk\u002F05.telemetry","i-lucide-activity",{"title":100,"icon":101,"path":102,"stem":103,"children":104,"page":34},"Better Auth","i-simple-icons-betterauth","\u002Flogging\u002Fbetter-auth","2.logging\u002F7.better-auth",[105,108,113,118,122],{"title":41,"path":106,"stem":107,"icon":44},"\u002Flogging\u002Fbetter-auth\u002Foverview","2.logging\u002F7.better-auth\u002F01.overview",{"title":109,"path":110,"stem":111,"icon":112},"Identify User","\u002Flogging\u002Fbetter-auth\u002Fidentify-user","2.logging\u002F7.better-auth\u002F02.identify-user","i-lucide-user-check",{"title":114,"path":115,"stem":116,"icon":117},"Middleware","\u002Flogging\u002Fbetter-auth\u002Fmiddleware","2.logging\u002F7.better-auth\u002F03.middleware","i-lucide-shield",{"title":119,"path":120,"stem":121,"icon":69},"Client Sync","\u002Flogging\u002Fbetter-auth\u002Fclient-sync","2.logging\u002F7.better-auth\u002F04.client-sync",{"title":123,"path":124,"stem":125,"icon":126},"Performance","\u002Flogging\u002Fbetter-auth\u002Fperformance","2.logging\u002F7.better-auth\u002F05.performance","i-lucide-gauge",{"title":128,"icon":129,"path":130,"stem":131,"children":132,"page":34},"Audit Logs","i-lucide-shield-check","\u002Flogging\u002Faudit","2.logging\u002F8.audit",[133,136,141,146,151,155],{"title":41,"path":134,"stem":135,"icon":44},"\u002Flogging\u002Faudit\u002Foverview","2.logging\u002F8.audit\u002F01.overview",{"title":137,"path":138,"stem":139,"icon":140},"Schema","\u002Flogging\u002Faudit\u002Fschema","2.logging\u002F8.audit\u002F02.schema","i-lucide-file-text",{"title":142,"path":143,"stem":144,"icon":145},"Recording","\u002Flogging\u002Faudit\u002Frecording","2.logging\u002F8.audit\u002F03.recording","i-lucide-pen-line",{"title":147,"path":148,"stem":149,"icon":150},"Drains","\u002Flogging\u002Faudit\u002Fpipeline","2.logging\u002F8.audit\u002F04.pipeline","i-lucide-link",{"title":152,"path":153,"stem":154,"icon":129},"Compliance","\u002Flogging\u002Faudit\u002Fcompliance","2.logging\u002F8.audit\u002F05.compliance",{"title":156,"path":157,"stem":158,"icon":64},"Recipes","\u002Flogging\u002Faudit\u002Frecipes","2.logging\u002F8.audit\u002F06.recipes",{"title":160,"path":161,"stem":162,"children":163,"page":34},"Core Concepts","\u002Fcore-concepts","3.core-concepts",[164,169,174,179,184,188,191,196],{"title":165,"path":166,"stem":167,"icon":168},"Lifecycle","\u002Fcore-concepts\u002Flifecycle","3.core-concepts\u002F0.lifecycle","i-lucide-arrow-right-left",{"title":170,"path":171,"stem":172,"icon":173},"Configuration","\u002Fcore-concepts\u002Fconfiguration","3.core-concepts\u002F1.configuration","i-lucide-settings",{"title":175,"path":176,"stem":177,"icon":178},"Sampling","\u002Fcore-concepts\u002Fsampling","3.core-concepts\u002F2.sampling","i-lucide-filter",{"title":180,"path":181,"stem":182,"icon":183},"Typed Fields","\u002Fcore-concepts\u002Ftyped-fields","3.core-concepts\u002F3.typed-fields","i-simple-icons-typescript",{"title":185,"path":186,"stem":187,"icon":129},"Best Practices","\u002Fcore-concepts\u002Fbest-practices","3.core-concepts\u002F4.best-practices",{"title":123,"path":189,"stem":190,"icon":126},"\u002Fcore-concepts\u002Fperformance","3.core-concepts\u002F5.performance",{"title":192,"path":193,"stem":194,"icon":195},"Vite Plugin","\u002Fcore-concepts\u002Fvite-plugin","3.core-concepts\u002F6.vite-plugin","i-custom-vite",{"title":197,"path":198,"stem":199,"icon":200},"Auto-Redaction","\u002Fcore-concepts\u002Fredaction","3.core-concepts\u002F7.redaction","i-lucide-eye-off",{"title":202,"path":203,"stem":204,"children":205,"page":34},"Frameworks","\u002Fframeworks","4.frameworks",[206,210,215,220,225,230,235,240,245,250,255,260,265,270,274,279,284],{"title":41,"path":207,"stem":208,"icon":209},"\u002Fframeworks\u002Foverview","4.frameworks\u002F00.overview","i-lucide-layout-grid",{"title":211,"path":212,"stem":213,"icon":214},"Nuxt","\u002Fframeworks\u002Fnuxt","4.frameworks\u002F01.nuxt","i-simple-icons-nuxtdotjs",{"title":216,"path":217,"stem":218,"icon":219},"Next.js","\u002Fframeworks\u002Fnextjs","4.frameworks\u002F02.nextjs","i-simple-icons-nextdotjs",{"title":221,"path":222,"stem":223,"icon":224},"SvelteKit","\u002Fframeworks\u002Fsveltekit","4.frameworks\u002F03.sveltekit","i-simple-icons-svelte",{"title":226,"path":227,"stem":228,"icon":229},"Nitro","\u002Fframeworks\u002Fnitro","4.frameworks\u002F04.nitro","i-custom-nitro",{"title":231,"path":232,"stem":233,"icon":234},"TanStack Start","\u002Fframeworks\u002Ftanstack-start","4.frameworks\u002F05.tanstack-start","i-custom-tanstack",{"title":236,"path":237,"stem":238,"icon":239},"NestJS","\u002Fframeworks\u002Fnestjs","4.frameworks\u002F06.nestjs","i-simple-icons-nestjs",{"title":241,"path":242,"stem":243,"icon":244},"Express","\u002Fframeworks\u002Fexpress","4.frameworks\u002F07.express","i-simple-icons-express",{"title":246,"path":247,"stem":248,"icon":249},"Hono","\u002Fframeworks\u002Fhono","4.frameworks\u002F08.hono","i-simple-icons-hono",{"title":251,"path":252,"stem":253,"icon":254},"Fastify","\u002Fframeworks\u002Ffastify","4.frameworks\u002F09.fastify","i-simple-icons-fastify",{"title":256,"path":257,"stem":258,"icon":259},"Elysia","\u002Fframeworks\u002Felysia","4.frameworks\u002F10.elysia","i-custom-elysia",{"title":261,"path":262,"stem":263,"icon":264},"React Router","\u002Fframeworks\u002Freact-router","4.frameworks\u002F11.react-router","i-custom-reactrouter",{"title":266,"path":267,"stem":268,"icon":269},"Cloudflare Workers","\u002Fframeworks\u002Fcloudflare-workers","4.frameworks\u002F12.cloudflare-workers","i-simple-icons-cloudflare",{"title":271,"path":272,"stem":273,"icon":183},"Standalone","\u002Fframeworks\u002Fstandalone","4.frameworks\u002F13.standalone",{"title":275,"path":276,"stem":277,"icon":278},"Astro","\u002Fframeworks\u002Fastro","4.frameworks\u002F14.astro","i-simple-icons-astro",{"title":280,"path":281,"stem":282,"icon":283},"AWS Lambda","\u002Fframeworks\u002Faws-lambda","4.frameworks\u002F16.aws-lambda","i-custom-lambda",{"title":285,"path":286,"stem":287,"icon":288},"Custom Integration","\u002Fframeworks\u002Fcustom-integration","4.frameworks\u002F17.custom-integration","i-lucide-puzzle",{"title":290,"path":291,"stem":292,"children":293,"page":34},"Build on top","\u002Fbuild-on-top","5.build-on-top",[294,299],{"title":295,"path":296,"stem":297,"icon":298},"Identity headers","\u002Fbuild-on-top\u002Fidentity-headers","5.build-on-top\u002F1.identity-headers","i-lucide-fingerprint",{"title":300,"path":301,"stem":302,"icon":303},"FS reader","\u002Fbuild-on-top\u002Ffs-reader","5.build-on-top\u002F4.fs-reader","i-lucide-folder-search",{"title":305,"path":306,"stem":307,"children":308,"page":34},"Adapters","\u002Fadapters","6.adapters",[309,312,352,367],{"title":41,"path":310,"stem":311,"icon":44},"\u002Fadapters\u002Foverview","6.adapters\u002F01.overview",{"title":313,"path":314,"stem":315,"children":316,"page":34},"Cloud destinations","\u002Fadapters\u002Fcloud","6.adapters\u002F02.cloud",[317,322,327,332,337,342,347],{"title":318,"path":319,"stem":320,"icon":321},"Axiom","\u002Fadapters\u002Fcloud\u002Faxiom","6.adapters\u002F02.cloud\u002F01.axiom","i-custom-axiom",{"title":323,"path":324,"stem":325,"icon":326},"OTLP","\u002Fadapters\u002Fcloud\u002Fotlp","6.adapters\u002F02.cloud\u002F02.otlp","i-simple-icons-opentelemetry",{"title":328,"path":329,"stem":330,"icon":331},"PostHog","\u002Fadapters\u002Fcloud\u002Fposthog","6.adapters\u002F02.cloud\u002F03.posthog","i-simple-icons-posthog",{"title":333,"path":334,"stem":335,"icon":336},"Sentry","\u002Fadapters\u002Fcloud\u002Fsentry","6.adapters\u002F02.cloud\u002F04.sentry","i-simple-icons-sentry",{"title":338,"path":339,"stem":340,"icon":341},"Better Stack","\u002Fadapters\u002Fcloud\u002Fbetter-stack","6.adapters\u002F02.cloud\u002F05.better-stack","i-simple-icons-betterstack",{"title":343,"path":344,"stem":345,"icon":346},"Datadog","\u002Fadapters\u002Fcloud\u002Fdatadog","6.adapters\u002F02.cloud\u002F06.datadog","i-simple-icons-datadog",{"title":348,"path":349,"stem":350,"icon":351},"HyperDX","\u002Fadapters\u002Fcloud\u002Fhyperdx","6.adapters\u002F02.cloud\u002F07.hyperdx","i-custom-hyperdx",{"title":353,"path":354,"stem":355,"children":356,"page":34},"Self-hosted","\u002Fadapters\u002Fself-hosted","6.adapters\u002F03.self-hosted",[357,362],{"title":358,"path":359,"stem":360,"icon":361},"File System","\u002Fadapters\u002Fself-hosted\u002Ffs","6.adapters\u002F03.self-hosted\u002F01.fs","i-lucide-hard-drive",{"title":363,"path":364,"stem":365,"icon":366},"NuxtHub","\u002Fadapters\u002Fself-hosted\u002Fnuxthub","6.adapters\u002F03.self-hosted\u002F02.nuxthub","i-simple-icons-nuxt",{"title":368,"path":369,"stem":370,"children":371,"page":34},"Building blocks","\u002Fadapters\u002Fbuilding-blocks","6.adapters\u002F04.building-blocks",[372,377,382,386],{"title":373,"path":374,"stem":375,"icon":376},"Pipeline","\u002Fadapters\u002Fbuilding-blocks\u002Fpipeline","6.adapters\u002F04.building-blocks\u002F01.pipeline","i-lucide-workflow",{"title":378,"path":379,"stem":380,"icon":381},"HTTP","\u002Fadapters\u002Fbuilding-blocks\u002Fhttp","6.adapters\u002F04.building-blocks\u002F02.http","i-lucide-globe",{"title":383,"path":384,"stem":385,"icon":83},"Custom Adapters","\u002Fadapters\u002Fbuilding-blocks\u002Fcustom","6.adapters\u002F04.building-blocks\u002F03.custom",{"title":387,"path":388,"stem":389,"icon":390},"Toolkit","\u002Fadapters\u002Fbuilding-blocks\u002Ftoolkit","6.adapters\u002F04.building-blocks\u002F04.toolkit","i-lucide-blocks",{"title":392,"path":393,"stem":394,"children":395,"page":34},"Enrichers","\u002Fenrichers","7.enrichers",[396,399,403],{"title":41,"path":397,"stem":398,"icon":28},"\u002Fenrichers\u002Foverview","7.enrichers\u002F1.overview",{"title":400,"path":401,"stem":402,"icon":288},"Built-in","\u002Fenrichers\u002Fbuilt-in","7.enrichers\u002F2.built-in",{"title":404,"path":405,"stem":406,"icon":83},"Custom","\u002Fenrichers\u002Fcustom","7.enrichers\u002F3.custom",{"id":408,"title":409,"body":410,"description":1128,"extension":1129,"links":1130,"meta":1135,"navigation":1136,"path":115,"seo":1137,"stem":116,"__hash__":1138},"docs\u002F2.logging\u002F7.better-auth\u002F03.middleware.md","createAuthMiddleware",{"type":411,"value":412,"toc":1122},"minimark",[413,424,579,593,597,608,711,715,718,803,806,861,883,887,893,1068,1080,1101,1105,1118],[414,415,416,419,420,423],"p",{},[417,418,409],"code",{}," wraps ",[417,421,422],{},"identifyUser"," with the things you need on every request: route filtering, session resolution timing, lifecycle hooks, and silent error handling. Call it once at startup, then use the returned function in your framework's middleware\u002Fhook system.",[425,426,432],"pre",{"className":427,"code":428,"filename":429,"language":430,"meta":431,"style":431},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","import { createAuthMiddleware } from 'evlog\u002Fbetter-auth'\n\nconst identify = createAuthMiddleware(auth, {\n  exclude: ['\u002Fapi\u002Fauth\u002F**', '\u002Fapi\u002Fpublic\u002F**'],\n  include: ['\u002Fapi\u002F**'],\n  maskEmail: true,\n})\n","server\u002Fmiddleware\u002Fauth-identify.ts","typescript","",[417,433,434,467,474,499,535,556,570],{"__ignoreMap":431},[435,436,439,443,447,451,454,457,460,464],"span",{"class":437,"line":438},"line",1,[435,440,442],{"class":441},"s7zQu","import",[435,444,446],{"class":445},"sMK4o"," {",[435,448,450],{"class":449},"sTEyZ"," createAuthMiddleware",[435,452,453],{"class":445}," }",[435,455,456],{"class":441}," from",[435,458,459],{"class":445}," '",[435,461,463],{"class":462},"sfazB","evlog\u002Fbetter-auth",[435,465,466],{"class":445},"'\n",[435,468,470],{"class":437,"line":469},2,[435,471,473],{"emptyLinePlaceholder":472},true,"\n",[435,475,477,481,484,487,490,493,496],{"class":437,"line":476},3,[435,478,480],{"class":479},"spNyl","const",[435,482,483],{"class":449}," identify ",[435,485,486],{"class":445},"=",[435,488,450],{"class":489},"s2Zo4",[435,491,492],{"class":449},"(auth",[435,494,495],{"class":445},",",[435,497,498],{"class":445}," {\n",[435,500,502,506,509,512,515,518,520,522,524,527,529,532],{"class":437,"line":501},4,[435,503,505],{"class":504},"swJcz","  exclude",[435,507,508],{"class":445},":",[435,510,511],{"class":449}," [",[435,513,514],{"class":445},"'",[435,516,517],{"class":462},"\u002Fapi\u002Fauth\u002F**",[435,519,514],{"class":445},[435,521,495],{"class":445},[435,523,459],{"class":445},[435,525,526],{"class":462},"\u002Fapi\u002Fpublic\u002F**",[435,528,514],{"class":445},[435,530,531],{"class":449},"]",[435,533,534],{"class":445},",\n",[435,536,538,541,543,545,547,550,552,554],{"class":437,"line":537},5,[435,539,540],{"class":504},"  include",[435,542,508],{"class":445},[435,544,511],{"class":449},[435,546,514],{"class":445},[435,548,549],{"class":462},"\u002Fapi\u002F**",[435,551,514],{"class":445},[435,553,531],{"class":449},[435,555,534],{"class":445},[435,557,559,562,564,568],{"class":437,"line":558},6,[435,560,561],{"class":504},"  maskEmail",[435,563,508],{"class":445},[435,565,567],{"class":566},"sfNiH"," true",[435,569,534],{"class":445},[435,571,573,576],{"class":437,"line":572},7,[435,574,575],{"class":445},"}",[435,577,578],{"class":449},")\n",[414,580,581,582,585,586,588,589,592],{},"The function signature is ",[417,583,584],{},"(log, headers, path?) => Promise\u003Cboolean>",". It resolves the session, calls ",[417,587,422],{},", captures timing into ",[417,590,591],{},"auth.resolvedIn",", fires lifecycle hooks, and silently catches errors so session resolution never breaks a request.",[594,595,85],"h2",{"id":596},"options",[414,598,599,600,607],{},"Inherits all ",[601,602,604,606],"a",{"href":603},"\u002Flogging\u002Fbetter-auth\u002Fidentify-user#options",[417,605,422],{}," options",", plus:",[609,610,611,630],"table",{},[612,613,614],"thead",{},[615,616,617,621,624,627],"tr",{},[618,619,620],"th",{},"Option",[618,622,623],{},"Type",[618,625,626],{},"Default",[618,628,629],{},"Description",[631,632,633,654,673,692],"tbody",{},[615,634,635,641,646,651],{},[636,637,638],"td",{},[417,639,640],{},"exclude",[636,642,643],{},[417,644,645],{},"string[]",[636,647,648],{},[417,649,650],{},"['\u002Fapi\u002Fauth\u002F**']",[636,652,653],{},"Route patterns to skip (glob).",[615,655,656,661,665,670],{},[636,657,658],{},[417,659,660],{},"include",[636,662,663],{},[417,664,645],{},[636,666,667],{},[417,668,669],{},"undefined",[636,671,672],{},"If set, only matching routes are resolved.",[615,674,675,680,685,689],{},[636,676,677],{},[417,678,679],{},"onIdentify",[636,681,682],{},[417,683,684],{},"(log, session) => void",[636,686,687],{},[417,688,669],{},[636,690,691],{},"Called after successful identification.",[615,693,694,699,704,708],{},[636,695,696],{},[417,697,698],{},"onAnonymous",[636,700,701],{},[417,702,703],{},"(log) => void",[636,705,706],{},[417,707,669],{},[636,709,710],{},"Called when no session is found.",[594,712,714],{"id":713},"route-filtering","Route Filtering",[414,716,717],{},"Skip Better Auth's own routes and any public endpoints to avoid wasted database queries:",[425,719,721],{"className":427,"code":720,"language":430,"meta":431,"style":431},"const identify = createAuthMiddleware(auth, {\n  exclude: [\n    '\u002Fapi\u002Fauth\u002F**',     \u002F\u002F Better Auth itself\n    '\u002Fapi\u002Fpublic\u002F**',   \u002F\u002F Public endpoints\n    '\u002Fapi\u002Fhealth',      \u002F\u002F Health checks\n  ],\n})\n",[417,722,723,739,748,763,776,790,797],{"__ignoreMap":431},[435,724,725,727,729,731,733,735,737],{"class":437,"line":438},[435,726,480],{"class":479},[435,728,483],{"class":449},[435,730,486],{"class":445},[435,732,450],{"class":489},[435,734,492],{"class":449},[435,736,495],{"class":445},[435,738,498],{"class":445},[435,740,741,743,745],{"class":437,"line":469},[435,742,505],{"class":504},[435,744,508],{"class":445},[435,746,747],{"class":449}," [\n",[435,749,750,753,755,757,759],{"class":437,"line":476},[435,751,752],{"class":445},"    '",[435,754,517],{"class":462},[435,756,514],{"class":445},[435,758,495],{"class":445},[435,760,762],{"class":761},"sHwdD","     \u002F\u002F Better Auth itself\n",[435,764,765,767,769,771,773],{"class":437,"line":501},[435,766,752],{"class":445},[435,768,526],{"class":462},[435,770,514],{"class":445},[435,772,495],{"class":445},[435,774,775],{"class":761},"   \u002F\u002F Public endpoints\n",[435,777,778,780,783,785,787],{"class":437,"line":537},[435,779,752],{"class":445},[435,781,782],{"class":462},"\u002Fapi\u002Fhealth",[435,784,514],{"class":445},[435,786,495],{"class":445},[435,788,789],{"class":761},"      \u002F\u002F Health checks\n",[435,791,792,795],{"class":437,"line":558},[435,793,794],{"class":449},"  ]",[435,796,534],{"class":445},[435,798,799,801],{"class":437,"line":572},[435,800,575],{"class":445},[435,802,578],{"class":449},[414,804,805],{},"For high-traffic apps, flip the model — only resolve sessions on routes that need them:",[425,807,809],{"className":427,"code":808,"language":430,"meta":431,"style":431},"const identify = createAuthMiddleware(auth, {\n  include: ['\u002Fapi\u002Fdashboard\u002F**', '\u002Fapi\u002Faccount\u002F**'],\n})\n",[417,810,811,827,855],{"__ignoreMap":431},[435,812,813,815,817,819,821,823,825],{"class":437,"line":438},[435,814,480],{"class":479},[435,816,483],{"class":449},[435,818,486],{"class":445},[435,820,450],{"class":489},[435,822,492],{"class":449},[435,824,495],{"class":445},[435,826,498],{"class":445},[435,828,829,831,833,835,837,840,842,844,846,849,851,853],{"class":437,"line":469},[435,830,540],{"class":504},[435,832,508],{"class":445},[435,834,511],{"class":449},[435,836,514],{"class":445},[435,838,839],{"class":462},"\u002Fapi\u002Fdashboard\u002F**",[435,841,514],{"class":445},[435,843,495],{"class":445},[435,845,459],{"class":445},[435,847,848],{"class":462},"\u002Fapi\u002Faccount\u002F**",[435,850,514],{"class":445},[435,852,531],{"class":449},[435,854,534],{"class":445},[435,856,857,859],{"class":437,"line":476},[435,858,575],{"class":445},[435,860,578],{"class":449},[414,862,863,865,866,868,869,872,873,876,877,879,880,882],{},[417,864,660],{}," and ",[417,867,640],{}," use glob patterns (",[417,870,871],{},"*",", ",[417,874,875],{},"**","). Provide both if you need granular control — ",[417,878,640],{}," wins over ",[417,881,660],{},".",[594,884,886],{"id":885},"lifecycle-hooks","Lifecycle Hooks",[414,888,889,890,892],{},"Use ",[417,891,679],{}," to react to user identification — for example, force-keep logs for premium users via tail sampling:",[425,894,896],{"className":427,"code":895,"filename":429,"language":430,"meta":431,"style":431},"const identify = createAuthMiddleware(auth, {\n  onIdentify: (log, session) => {\n    if (session.user.plan === 'enterprise') {\n      log.set({ _forceKeep: true })\n    }\n  },\n  onAnonymous: (log) => {\n    log.set({ anonymous: true })\n  },\n})\n",[417,897,898,914,941,977,1004,1009,1014,1031,1056,1061],{"__ignoreMap":431},[435,899,900,902,904,906,908,910,912],{"class":437,"line":438},[435,901,480],{"class":479},[435,903,483],{"class":449},[435,905,486],{"class":445},[435,907,450],{"class":489},[435,909,492],{"class":449},[435,911,495],{"class":445},[435,913,498],{"class":445},[435,915,916,919,921,924,928,930,933,936,939],{"class":437,"line":469},[435,917,918],{"class":489},"  onIdentify",[435,920,508],{"class":445},[435,922,923],{"class":445}," (",[435,925,927],{"class":926},"sHdIc","log",[435,929,495],{"class":445},[435,931,932],{"class":926}," session",[435,934,935],{"class":445},")",[435,937,938],{"class":479}," =>",[435,940,498],{"class":445},[435,942,943,946,948,951,953,956,958,961,964,966,969,971,974],{"class":437,"line":476},[435,944,945],{"class":441},"    if",[435,947,923],{"class":504},[435,949,950],{"class":449},"session",[435,952,882],{"class":445},[435,954,955],{"class":449},"user",[435,957,882],{"class":445},[435,959,960],{"class":449},"plan",[435,962,963],{"class":445}," ===",[435,965,459],{"class":445},[435,967,968],{"class":462},"enterprise",[435,970,514],{"class":445},[435,972,973],{"class":504},") ",[435,975,976],{"class":445},"{\n",[435,978,979,982,984,987,990,993,996,998,1000,1002],{"class":437,"line":501},[435,980,981],{"class":449},"      log",[435,983,882],{"class":445},[435,985,986],{"class":489},"set",[435,988,989],{"class":504},"(",[435,991,992],{"class":445},"{",[435,994,995],{"class":504}," _forceKeep",[435,997,508],{"class":445},[435,999,567],{"class":566},[435,1001,453],{"class":445},[435,1003,578],{"class":504},[435,1005,1006],{"class":437,"line":537},[435,1007,1008],{"class":445},"    }\n",[435,1010,1011],{"class":437,"line":558},[435,1012,1013],{"class":445},"  },\n",[435,1015,1016,1019,1021,1023,1025,1027,1029],{"class":437,"line":572},[435,1017,1018],{"class":489},"  onAnonymous",[435,1020,508],{"class":445},[435,1022,923],{"class":445},[435,1024,927],{"class":926},[435,1026,935],{"class":445},[435,1028,938],{"class":479},[435,1030,498],{"class":445},[435,1032,1034,1037,1039,1041,1043,1045,1048,1050,1052,1054],{"class":437,"line":1033},8,[435,1035,1036],{"class":449},"    log",[435,1038,882],{"class":445},[435,1040,986],{"class":489},[435,1042,989],{"class":504},[435,1044,992],{"class":445},[435,1046,1047],{"class":504}," anonymous",[435,1049,508],{"class":445},[435,1051,567],{"class":566},[435,1053,453],{"class":445},[435,1055,578],{"class":504},[435,1057,1059],{"class":437,"line":1058},9,[435,1060,1013],{"class":445},[435,1062,1064,1066],{"class":437,"line":1063},10,[435,1065,575],{"class":445},[435,1067,578],{"class":449},[414,1069,1070,1071,1073,1074,1076,1077,1079],{},"Hooks fire after the session is resolved and ",[417,1072,422],{}," has set its fields. They run on every request that passes the ",[417,1075,660],{},"\u002F",[417,1078,640],{}," filter, so keep them fast and side-effect-free.",[1081,1082,1083,1088],"tip",{},[414,1084,1085,1086,508],{},"Common patterns for ",[417,1087,679],{},[1089,1090,1091,1095,1098],"ul",{},[1092,1093,1094],"li",{},"Force-keep audit logs for admins or high-value plans.",[1092,1096,1097],{},"Tag the request with feature flags or tenant info loaded from the session.",[1092,1099,1100],{},"Increment a per-user counter for billing.",[594,1102,1104],{"id":1103},"error-handling","Error Handling",[414,1106,1107,1108,1111,1112,865,1114,1117],{},"The middleware catches every error from ",[417,1109,1110],{},"getSession"," and logs nothing — your request keeps flowing whether the auth backend is up or down. The wide event still includes ",[417,1113,591],{},[417,1115,1116],{},"auth.identified: false"," so you can alert on session resolution health from your dashboards.",[1119,1120,1121],"style",{},"html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}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 .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}",{"title":431,"searchDepth":469,"depth":469,"links":1123},[1124,1125,1126,1127],{"id":596,"depth":469,"text":85},{"id":713,"depth":469,"text":714},{"id":885,"depth":469,"text":886},{"id":1103,"depth":469,"text":1104},"Framework-agnostic factory with route filtering, session timing, and lifecycle hooks. Call it once at startup and reuse across requests.","md",[1131,1134],{"label":109,"icon":112,"to":110,"color":1132,"variant":1133},"neutral","subtle",{"label":123,"icon":126,"to":124,"color":1132,"variant":1133},{},{"title":114,"icon":117},{"title":409,"description":1128},"ZixjaO8WGr0DIrrPIzupQI4fZZLVn2bM3EBBAoqYgdg",[1140,1142],{"title":109,"path":110,"stem":111,"description":1141,"icon":112,"children":-1},"The core building block — extract safe user fields, mask emails, and capture plugin data (organizations, roles, 2FA) from a Better Auth session.",{"title":119,"path":120,"stem":121,"description":1143,"icon":69,"children":-1},"Mirror the server-side user identity into client-side logs by watching the Better Auth session and calling setIdentity.",1778327129285]