mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-24 15:08:44 -05:00
* Initial * isMod etc. * canPerformAdminActions * isAdmin * isSupporter * admin override * Lohi * Badge manage with new permissions style * Refactor badge loading logic * Move funcs * Delete permissions.ts * DRY
29 lines
1017 B
TypeScript
29 lines
1017 B
TypeScript
import type { LoaderFunctionArgs } from "@remix-run/node";
|
|
import { isImpersonating, requireUser } from "~/features/auth/core/user.server";
|
|
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
|
import { requireRole } from "~/modules/permissions/guards.server";
|
|
import { parseSafeSearchParams } from "~/utils/remix.server";
|
|
import { adminActionSearchParamsSchema } from "../admin-schemas";
|
|
|
|
export const loader = async ({ request }: LoaderFunctionArgs) => {
|
|
// allow unauthorized access in development mode to access impersonation controls
|
|
if (process.env.NODE_ENV === "production") {
|
|
const user = await requireUser(request);
|
|
requireRole(user, "STAFF");
|
|
}
|
|
|
|
const parsedSearchParams = parseSafeSearchParams({
|
|
request,
|
|
schema: adminActionSearchParamsSchema,
|
|
});
|
|
|
|
return {
|
|
isImpersonating: await isImpersonating(request),
|
|
friendCodeSearchUsers: parsedSearchParams.success
|
|
? await UserRepository.findByFriendCode(
|
|
parsedSearchParams.data.friendCode,
|
|
)
|
|
: [],
|
|
};
|
|
};
|