mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-03 11:45:57 -05:00
29 lines
954 B
TypeScript
29 lines
954 B
TypeScript
import type { LoaderFunctionArgs } from "@remix-run/node";
|
|
import { redirect } from "@remix-run/node";
|
|
import { getUserId, isImpersonating } from "~/features/auth/core/user.server";
|
|
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
|
import { isMod } from "~/permissions";
|
|
import { parseSafeSearchParams } from "~/utils/remix.server";
|
|
import { adminActionSearchParamsSchema } from "../admin-schemas";
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
const user = await getUserId(request);
|
|
const parsedSearchParams = parseSafeSearchParams({
|
|
request,
|
|
schema: adminActionSearchParamsSchema,
|
|
});
|
|
|
|
if (process.env.NODE_ENV === "production" && !isMod(user)) {
|
|
throw redirect("/");
|
|
}
|
|
|
|
return {
|
|
isImpersonating: await isImpersonating(request),
|
|
friendCodeSearchUsers: parsedSearchParams.success
|
|
? await UserRepository.findByFriendCode(
|
|
parsedSearchParams.data.friendCode,
|
|
)
|
|
: [],
|
|
};
|
|
};
|