v1.0.25
This commit is contained in:
1 parent
c210ef0a8e
commit
afee09866d
55 files changed
+7767
-131
No files matched your search
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Request-scoped context using AsyncLocalStorage.
|
||||
*
|
||||
* The hook sets the authenticated user (from cookie or Bearer token)
|
||||
* and wraps resolve() in requestContext.run(). Downstream code like
|
||||
* authorize() reads the pre-resolved user from here instead of
|
||||
* re-validating the session.
|
||||
*/
|
||||
|
||||
import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
import type { AuthenticatedUser } from './auth';
|
||||
|
||||
export interface RequestContext {
|
||||
user: AuthenticatedUser | null;
|
||||
authEnabled: boolean;
|
||||
authMethod: 'cookie' | 'bearer' | 'none';
|
||||
}
|
||||
|
||||
export const requestContext = new AsyncLocalStorage<RequestContext>();
|
||||
|
||||
export function getRequestContext(): RequestContext | undefined {
|
||||
return requestContext.getStore();
|
||||
}
|
||||
Reference in new issue
Block a user