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:
2026-01-11 14:56:10 -06:00
parent afcb447b2b
commit 55f5cc699d
3 changed files with 36 additions and 4 deletions

View File

@@ -1,9 +1,10 @@
// services.ts
import { AuthService } from "../auth";
import { getCurrentUser } from "../context";
import { db, migrate, migrationStatus, PostgresAuthStore } from "../database";
import { getLogs, log } from "../logging";
import { anonymousUser, type User } from "../user";
import type { MaybeUser } from "../user";
const database = {
db,
@@ -29,8 +30,8 @@ const misc = {
};
const session = {
getUser: (): User => {
return anonymousUser;
getUser: (): MaybeUser => {
return getCurrentUser();
},
};