wip league admin tools
This commit is contained in:
25
apps/api/src/domain/auth/getActorFromRequestContext.ts
Normal file
25
apps/api/src/domain/auth/getActorFromRequestContext.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { getHttpRequestContext } from '@adapters/http/RequestContext';
|
||||
|
||||
export type Actor = {
|
||||
userId: string;
|
||||
driverId: string;
|
||||
};
|
||||
|
||||
type AuthenticatedRequest = {
|
||||
user?: { userId: string };
|
||||
};
|
||||
|
||||
export function getActorFromRequestContext(): Actor {
|
||||
const ctx = getHttpRequestContext();
|
||||
const req = ctx.req as unknown as AuthenticatedRequest;
|
||||
|
||||
const userId = req.user?.userId;
|
||||
if (!userId) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
// Current canonical mapping:
|
||||
// - The authenticated session identity is `userId`.
|
||||
// - In the current system, that `userId` is also treated as the performer `driverId`.
|
||||
return { userId, driverId: userId };
|
||||
}
|
||||
Reference in New Issue
Block a user