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