mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 01:09:02 -05:00
32 lines
1022 B
TypeScript
32 lines
1022 B
TypeScript
import { type LoaderFunctionArgs, redirect } from "react-router";
|
|
import * as AdminRepository from "~/features/admin/AdminRepository.server";
|
|
import {
|
|
IMPERSONATED_SESSION_KEY,
|
|
SESSION_KEY,
|
|
} from "~/features/auth/core/authenticator.server";
|
|
import { authSessionStorage } from "~/features/auth/core/session.server";
|
|
import type { Nullish } from "~/utils/types";
|
|
import { userIsBanned } from "../core/banned.server";
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
const userId = await getUserIdEvenIfBanned(request);
|
|
|
|
if (!userId || !userIsBanned(userId)) return redirect("/");
|
|
|
|
const bannedStatus = (await AdminRepository.allBannedUsers()).get(userId)!;
|
|
|
|
return {
|
|
banned: bannedStatus.banned,
|
|
reason: bannedStatus.bannedReason,
|
|
};
|
|
};
|
|
|
|
async function getUserIdEvenIfBanned(
|
|
request: Request,
|
|
): Promise<Nullish<number>> {
|
|
const session = await authSessionStorage.getSession(
|
|
request.headers.get("Cookie"),
|
|
);
|
|
return session.get(IMPERSONATED_SESSION_KEY) ?? session.get(SESSION_KEY);
|
|
}
|