mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-23 19:04:28 -05:00
27 lines
716 B
TypeScript
27 lines
716 B
TypeScript
import { IMPERSONATED_SESSION_KEY } from "./authenticator.server";
|
|
import { authSessionStorage } from "./session.server";
|
|
import { type AuthenticatedUser, getUserContext } from "./user-context.server";
|
|
|
|
export type { AuthenticatedUser };
|
|
|
|
export function getUser(): AuthenticatedUser | undefined {
|
|
const context = getUserContext();
|
|
return context.user;
|
|
}
|
|
|
|
export function requireUser(): AuthenticatedUser {
|
|
const user = getUser();
|
|
|
|
if (!user) throw new Response(null, { status: 401 });
|
|
|
|
return user;
|
|
}
|
|
|
|
export async function isImpersonating(request: Request) {
|
|
const session = await authSessionStorage.getSession(
|
|
request.headers.get("Cookie"),
|
|
);
|
|
|
|
return Boolean(session.get(IMPERSONATED_SESSION_KEY));
|
|
}
|