[{"data":1,"prerenderedAt":1139},["ShallowReactive",2],{"navigation_docs":3,"-logging-better-auth-middleware":402,"-logging-better-auth-middleware-surround":1134},[4,35,159,201,289,299,386],{"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],{"title":295,"path":296,"stem":297,"icon":298},"FS reader","\u002Fbuild-on-top\u002Ffs-reader","5.build-on-top\u002F4.fs-reader","i-lucide-folder-search",{"title":300,"path":301,"stem":302,"children":303,"page":34},"Adapters","\u002Fadapters","6.adapters",[304,307,347,362],{"title":41,"path":305,"stem":306,"icon":44},"\u002Fadapters\u002Foverview","6.adapters\u002F01.overview",{"title":308,"path":309,"stem":310,"children":311,"page":34},"Cloud destinations","\u002Fadapters\u002Fcloud","6.adapters\u002F02.cloud",[312,317,322,327,332,337,342],{"title":313,"path":314,"stem":315,"icon":316},"Axiom","\u002Fadapters\u002Fcloud\u002Faxiom","6.adapters\u002F02.cloud\u002F01.axiom","i-custom-axiom",{"title":318,"path":319,"stem":320,"icon":321},"OTLP","\u002Fadapters\u002Fcloud\u002Fotlp","6.adapters\u002F02.cloud\u002F02.otlp","i-simple-icons-opentelemetry",{"title":323,"path":324,"stem":325,"icon":326},"PostHog","\u002Fadapters\u002Fcloud\u002Fposthog","6.adapters\u002F02.cloud\u002F03.posthog","i-simple-icons-posthog",{"title":328,"path":329,"stem":330,"icon":331},"Sentry","\u002Fadapters\u002Fcloud\u002Fsentry","6.adapters\u002F02.cloud\u002F04.sentry","i-simple-icons-sentry",{"title":333,"path":334,"stem":335,"icon":336},"Better Stack","\u002Fadapters\u002Fcloud\u002Fbetter-stack","6.adapters\u002F02.cloud\u002F05.better-stack","i-simple-icons-betterstack",{"title":338,"path":339,"stem":340,"icon":341},"Datadog","\u002Fadapters\u002Fcloud\u002Fdatadog","6.adapters\u002F02.cloud\u002F06.datadog","i-simple-icons-datadog",{"title":343,"path":344,"stem":345,"icon":346},"HyperDX","\u002Fadapters\u002Fcloud\u002Fhyperdx","6.adapters\u002F02.cloud\u002F07.hyperdx","i-custom-hyperdx",{"title":348,"path":349,"stem":350,"children":351,"page":34},"Self-hosted","\u002Fadapters\u002Fself-hosted","6.adapters\u002F03.self-hosted",[352,357],{"title":353,"path":354,"stem":355,"icon":356},"File System","\u002Fadapters\u002Fself-hosted\u002Ffs","6.adapters\u002F03.self-hosted\u002F01.fs","i-lucide-hard-drive",{"title":358,"path":359,"stem":360,"icon":361},"NuxtHub","\u002Fadapters\u002Fself-hosted\u002Fnuxthub","6.adapters\u002F03.self-hosted\u002F02.nuxthub","i-simple-icons-nuxt",{"title":363,"path":364,"stem":365,"children":366,"page":34},"Building blocks","\u002Fadapters\u002Fbuilding-blocks","6.adapters\u002F04.building-blocks",[367,372,377,381],{"title":368,"path":369,"stem":370,"icon":371},"Pipeline","\u002Fadapters\u002Fbuilding-blocks\u002Fpipeline","6.adapters\u002F04.building-blocks\u002F01.pipeline","i-lucide-workflow",{"title":373,"path":374,"stem":375,"icon":376},"HTTP","\u002Fadapters\u002Fbuilding-blocks\u002Fhttp","6.adapters\u002F04.building-blocks\u002F02.http","i-lucide-globe",{"title":378,"path":379,"stem":380,"icon":83},"Custom Adapters","\u002Fadapters\u002Fbuilding-blocks\u002Fcustom","6.adapters\u002F04.building-blocks\u002F03.custom",{"title":382,"path":383,"stem":384,"icon":385},"Toolkit","\u002Fadapters\u002Fbuilding-blocks\u002Ftoolkit","6.adapters\u002F04.building-blocks\u002F04.toolkit","i-lucide-blocks",{"title":387,"path":388,"stem":389,"children":390,"page":34},"Enrichers","\u002Fenrichers","7.enrichers",[391,394,398],{"title":41,"path":392,"stem":393,"icon":28},"\u002Fenrichers\u002Foverview","7.enrichers\u002F1.overview",{"title":395,"path":396,"stem":397,"icon":288},"Built-in","\u002Fenrichers\u002Fbuilt-in","7.enrichers\u002F2.built-in",{"title":399,"path":400,"stem":401,"icon":83},"Custom","\u002Fenrichers\u002Fcustom","7.enrichers\u002F3.custom",{"id":403,"title":404,"body":405,"description":1123,"extension":1124,"links":1125,"meta":1130,"navigation":1131,"path":115,"seo":1132,"stem":116,"__hash__":1133},"docs\u002F2.logging\u002F7.better-auth\u002F03.middleware.md","createAuthMiddleware",{"type":406,"value":407,"toc":1117},"minimark",[408,419,574,588,592,603,706,710,713,798,801,856,878,882,888,1063,1075,1096,1100,1113],[409,410,411,414,415,418],"p",{},[412,413,404],"code",{}," wraps ",[412,416,417],{},"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.",[420,421,427],"pre",{"className":422,"code":423,"filename":424,"language":425,"meta":426,"style":426},"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","",[412,428,429,462,469,494,530,551,565],{"__ignoreMap":426},[430,431,434,438,442,446,449,452,455,459],"span",{"class":432,"line":433},"line",1,[430,435,437],{"class":436},"s7zQu","import",[430,439,441],{"class":440},"sMK4o"," {",[430,443,445],{"class":444},"sTEyZ"," createAuthMiddleware",[430,447,448],{"class":440}," }",[430,450,451],{"class":436}," from",[430,453,454],{"class":440}," '",[430,456,458],{"class":457},"sfazB","evlog\u002Fbetter-auth",[430,460,461],{"class":440},"'\n",[430,463,465],{"class":432,"line":464},2,[430,466,468],{"emptyLinePlaceholder":467},true,"\n",[430,470,472,476,479,482,485,488,491],{"class":432,"line":471},3,[430,473,475],{"class":474},"spNyl","const",[430,477,478],{"class":444}," identify ",[430,480,481],{"class":440},"=",[430,483,445],{"class":484},"s2Zo4",[430,486,487],{"class":444},"(auth",[430,489,490],{"class":440},",",[430,492,493],{"class":440}," {\n",[430,495,497,501,504,507,510,513,515,517,519,522,524,527],{"class":432,"line":496},4,[430,498,500],{"class":499},"swJcz","  exclude",[430,502,503],{"class":440},":",[430,505,506],{"class":444}," [",[430,508,509],{"class":440},"'",[430,511,512],{"class":457},"\u002Fapi\u002Fauth\u002F**",[430,514,509],{"class":440},[430,516,490],{"class":440},[430,518,454],{"class":440},[430,520,521],{"class":457},"\u002Fapi\u002Fpublic\u002F**",[430,523,509],{"class":440},[430,525,526],{"class":444},"]",[430,528,529],{"class":440},",\n",[430,531,533,536,538,540,542,545,547,549],{"class":432,"line":532},5,[430,534,535],{"class":499},"  include",[430,537,503],{"class":440},[430,539,506],{"class":444},[430,541,509],{"class":440},[430,543,544],{"class":457},"\u002Fapi\u002F**",[430,546,509],{"class":440},[430,548,526],{"class":444},[430,550,529],{"class":440},[430,552,554,557,559,563],{"class":432,"line":553},6,[430,555,556],{"class":499},"  maskEmail",[430,558,503],{"class":440},[430,560,562],{"class":561},"sfNiH"," true",[430,564,529],{"class":440},[430,566,568,571],{"class":432,"line":567},7,[430,569,570],{"class":440},"}",[430,572,573],{"class":444},")\n",[409,575,576,577,580,581,583,584,587],{},"The function signature is ",[412,578,579],{},"(log, headers, path?) => Promise\u003Cboolean>",". It resolves the session, calls ",[412,582,417],{},", captures timing into ",[412,585,586],{},"auth.resolvedIn",", fires lifecycle hooks, and silently catches errors so session resolution never breaks a request.",[589,590,85],"h2",{"id":591},"options",[409,593,594,595,602],{},"Inherits all ",[596,597,599,601],"a",{"href":598},"\u002Flogging\u002Fbetter-auth\u002Fidentify-user#options",[412,600,417],{}," options",", plus:",[604,605,606,625],"table",{},[607,608,609],"thead",{},[610,611,612,616,619,622],"tr",{},[613,614,615],"th",{},"Option",[613,617,618],{},"Type",[613,620,621],{},"Default",[613,623,624],{},"Description",[626,627,628,649,668,687],"tbody",{},[610,629,630,636,641,646],{},[631,632,633],"td",{},[412,634,635],{},"exclude",[631,637,638],{},[412,639,640],{},"string[]",[631,642,643],{},[412,644,645],{},"['\u002Fapi\u002Fauth\u002F**']",[631,647,648],{},"Route patterns to skip (glob).",[610,650,651,656,660,665],{},[631,652,653],{},[412,654,655],{},"include",[631,657,658],{},[412,659,640],{},[631,661,662],{},[412,663,664],{},"undefined",[631,666,667],{},"If set, only matching routes are resolved.",[610,669,670,675,680,684],{},[631,671,672],{},[412,673,674],{},"onIdentify",[631,676,677],{},[412,678,679],{},"(log, session) => void",[631,681,682],{},[412,683,664],{},[631,685,686],{},"Called after successful identification.",[610,688,689,694,699,703],{},[631,690,691],{},[412,692,693],{},"onAnonymous",[631,695,696],{},[412,697,698],{},"(log) => void",[631,700,701],{},[412,702,664],{},[631,704,705],{},"Called when no session is found.",[589,707,709],{"id":708},"route-filtering","Route Filtering",[409,711,712],{},"Skip Better Auth's own routes and any public endpoints to avoid wasted database queries:",[420,714,716],{"className":422,"code":715,"language":425,"meta":426,"style":426},"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",[412,717,718,734,743,758,771,785,792],{"__ignoreMap":426},[430,719,720,722,724,726,728,730,732],{"class":432,"line":433},[430,721,475],{"class":474},[430,723,478],{"class":444},[430,725,481],{"class":440},[430,727,445],{"class":484},[430,729,487],{"class":444},[430,731,490],{"class":440},[430,733,493],{"class":440},[430,735,736,738,740],{"class":432,"line":464},[430,737,500],{"class":499},[430,739,503],{"class":440},[430,741,742],{"class":444}," [\n",[430,744,745,748,750,752,754],{"class":432,"line":471},[430,746,747],{"class":440},"    '",[430,749,512],{"class":457},[430,751,509],{"class":440},[430,753,490],{"class":440},[430,755,757],{"class":756},"sHwdD","     \u002F\u002F Better Auth itself\n",[430,759,760,762,764,766,768],{"class":432,"line":496},[430,761,747],{"class":440},[430,763,521],{"class":457},[430,765,509],{"class":440},[430,767,490],{"class":440},[430,769,770],{"class":756},"   \u002F\u002F Public endpoints\n",[430,772,773,775,778,780,782],{"class":432,"line":532},[430,774,747],{"class":440},[430,776,777],{"class":457},"\u002Fapi\u002Fhealth",[430,779,509],{"class":440},[430,781,490],{"class":440},[430,783,784],{"class":756},"      \u002F\u002F Health checks\n",[430,786,787,790],{"class":432,"line":553},[430,788,789],{"class":444},"  ]",[430,791,529],{"class":440},[430,793,794,796],{"class":432,"line":567},[430,795,570],{"class":440},[430,797,573],{"class":444},[409,799,800],{},"For high-traffic apps, flip the model — only resolve sessions on routes that need them:",[420,802,804],{"className":422,"code":803,"language":425,"meta":426,"style":426},"const identify = createAuthMiddleware(auth, {\n  include: ['\u002Fapi\u002Fdashboard\u002F**', '\u002Fapi\u002Faccount\u002F**'],\n})\n",[412,805,806,822,850],{"__ignoreMap":426},[430,807,808,810,812,814,816,818,820],{"class":432,"line":433},[430,809,475],{"class":474},[430,811,478],{"class":444},[430,813,481],{"class":440},[430,815,445],{"class":484},[430,817,487],{"class":444},[430,819,490],{"class":440},[430,821,493],{"class":440},[430,823,824,826,828,830,832,835,837,839,841,844,846,848],{"class":432,"line":464},[430,825,535],{"class":499},[430,827,503],{"class":440},[430,829,506],{"class":444},[430,831,509],{"class":440},[430,833,834],{"class":457},"\u002Fapi\u002Fdashboard\u002F**",[430,836,509],{"class":440},[430,838,490],{"class":440},[430,840,454],{"class":440},[430,842,843],{"class":457},"\u002Fapi\u002Faccount\u002F**",[430,845,509],{"class":440},[430,847,526],{"class":444},[430,849,529],{"class":440},[430,851,852,854],{"class":432,"line":471},[430,853,570],{"class":440},[430,855,573],{"class":444},[409,857,858,860,861,863,864,867,868,871,872,874,875,877],{},[412,859,655],{}," and ",[412,862,635],{}," use glob patterns (",[412,865,866],{},"*",", ",[412,869,870],{},"**","). Provide both if you need granular control — ",[412,873,635],{}," wins over ",[412,876,655],{},".",[589,879,881],{"id":880},"lifecycle-hooks","Lifecycle Hooks",[409,883,884,885,887],{},"Use ",[412,886,674],{}," to react to user identification — for example, force-keep logs for premium users via tail sampling:",[420,889,891],{"className":422,"code":890,"filename":424,"language":425,"meta":426,"style":426},"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",[412,892,893,909,936,972,999,1004,1009,1026,1051,1056],{"__ignoreMap":426},[430,894,895,897,899,901,903,905,907],{"class":432,"line":433},[430,896,475],{"class":474},[430,898,478],{"class":444},[430,900,481],{"class":440},[430,902,445],{"class":484},[430,904,487],{"class":444},[430,906,490],{"class":440},[430,908,493],{"class":440},[430,910,911,914,916,919,923,925,928,931,934],{"class":432,"line":464},[430,912,913],{"class":484},"  onIdentify",[430,915,503],{"class":440},[430,917,918],{"class":440}," (",[430,920,922],{"class":921},"sHdIc","log",[430,924,490],{"class":440},[430,926,927],{"class":921}," session",[430,929,930],{"class":440},")",[430,932,933],{"class":474}," =>",[430,935,493],{"class":440},[430,937,938,941,943,946,948,951,953,956,959,961,964,966,969],{"class":432,"line":471},[430,939,940],{"class":436},"    if",[430,942,918],{"class":499},[430,944,945],{"class":444},"session",[430,947,877],{"class":440},[430,949,950],{"class":444},"user",[430,952,877],{"class":440},[430,954,955],{"class":444},"plan",[430,957,958],{"class":440}," ===",[430,960,454],{"class":440},[430,962,963],{"class":457},"enterprise",[430,965,509],{"class":440},[430,967,968],{"class":499},") ",[430,970,971],{"class":440},"{\n",[430,973,974,977,979,982,985,988,991,993,995,997],{"class":432,"line":496},[430,975,976],{"class":444},"      log",[430,978,877],{"class":440},[430,980,981],{"class":484},"set",[430,983,984],{"class":499},"(",[430,986,987],{"class":440},"{",[430,989,990],{"class":499}," _forceKeep",[430,992,503],{"class":440},[430,994,562],{"class":561},[430,996,448],{"class":440},[430,998,573],{"class":499},[430,1000,1001],{"class":432,"line":532},[430,1002,1003],{"class":440},"    }\n",[430,1005,1006],{"class":432,"line":553},[430,1007,1008],{"class":440},"  },\n",[430,1010,1011,1014,1016,1018,1020,1022,1024],{"class":432,"line":567},[430,1012,1013],{"class":484},"  onAnonymous",[430,1015,503],{"class":440},[430,1017,918],{"class":440},[430,1019,922],{"class":921},[430,1021,930],{"class":440},[430,1023,933],{"class":474},[430,1025,493],{"class":440},[430,1027,1029,1032,1034,1036,1038,1040,1043,1045,1047,1049],{"class":432,"line":1028},8,[430,1030,1031],{"class":444},"    log",[430,1033,877],{"class":440},[430,1035,981],{"class":484},[430,1037,984],{"class":499},[430,1039,987],{"class":440},[430,1041,1042],{"class":499}," anonymous",[430,1044,503],{"class":440},[430,1046,562],{"class":561},[430,1048,448],{"class":440},[430,1050,573],{"class":499},[430,1052,1054],{"class":432,"line":1053},9,[430,1055,1008],{"class":440},[430,1057,1059,1061],{"class":432,"line":1058},10,[430,1060,570],{"class":440},[430,1062,573],{"class":444},[409,1064,1065,1066,1068,1069,1071,1072,1074],{},"Hooks fire after the session is resolved and ",[412,1067,417],{}," has set its fields. They run on every request that passes the ",[412,1070,655],{},"\u002F",[412,1073,635],{}," filter, so keep them fast and side-effect-free.",[1076,1077,1078,1083],"tip",{},[409,1079,1080,1081,503],{},"Common patterns for ",[412,1082,674],{},[1084,1085,1086,1090,1093],"ul",{},[1087,1088,1089],"li",{},"Force-keep audit logs for admins or high-value plans.",[1087,1091,1092],{},"Tag the request with feature flags or tenant info loaded from the session.",[1087,1094,1095],{},"Increment a per-user counter for billing.",[589,1097,1099],{"id":1098},"error-handling","Error Handling",[409,1101,1102,1103,1106,1107,860,1109,1112],{},"The middleware catches every error from ",[412,1104,1105],{},"getSession"," and logs nothing — your request keeps flowing whether the auth backend is up or down. The wide event still includes ",[412,1108,586],{},[412,1110,1111],{},"auth.identified: false"," so you can alert on session resolution health from your dashboards.",[1114,1115,1116],"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":426,"searchDepth":464,"depth":464,"links":1118},[1119,1120,1121,1122],{"id":591,"depth":464,"text":85},{"id":708,"depth":464,"text":709},{"id":880,"depth":464,"text":881},{"id":1098,"depth":464,"text":1099},"Framework-agnostic factory with route filtering, session timing, and lifecycle hooks. Call it once at startup and reuse across requests.","md",[1126,1129],{"label":109,"icon":112,"to":110,"color":1127,"variant":1128},"neutral","subtle",{"label":123,"icon":126,"to":124,"color":1127,"variant":1128},{},{"title":114,"icon":117},{"title":404,"description":1123},"ZixjaO8WGr0DIrrPIzupQI4fZZLVn2bM3EBBAoqYgdg",[1135,1137],{"title":109,"path":110,"stem":111,"description":1136,"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":1138,"icon":69,"children":-1},"Mirror the server-side user identity into client-side logs by watching the Better Auth session and calling setIdentity.",1778325968546]