sendou.ink/app/features/admin/loaders/admin.server.ts
Kalle d2551d2706
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Global roles refactor (#2212)
* 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
2025-04-21 23:51:30 +03:00

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,
)
: [],
};
};