Add request-scoped context for session.getUser()
Use AsyncLocalStorage to provide request context so services can access the current user without needing Call passed through every function. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import { match } from "path-to-regexp";
|
||||
import { Session } from "./auth";
|
||||
import { cli } from "./cli";
|
||||
import { contentTypes } from "./content-types";
|
||||
import { runWithContext } from "./context";
|
||||
import { httpCodes } from "./http-codes";
|
||||
import { routes } from "./routes";
|
||||
import { services } from "./services";
|
||||
@@ -75,7 +76,10 @@ routes.forEach((route: Route, _idx: number, _allRoutes: Route[]) => {
|
||||
};
|
||||
|
||||
try {
|
||||
const retval = await route.handler(req);
|
||||
const retval = await runWithContext(
|
||||
{ user: auth.user },
|
||||
() => route.handler(req),
|
||||
);
|
||||
return retval;
|
||||
} catch (error) {
|
||||
// Handle authentication errors
|
||||
|
||||
Reference in New Issue
Block a user