Files
sendou.ink/app/features/api/core/perms.ts
2026-09-02 21:02:01 +03:00

17 lines
758 B
TypeScript

import type { AuthenticatedUser } from "~/features/auth/core/user.server";
import * as TournamentOrganizationRepository from "~/features/tournament-organization/TournamentOrganizationRepository.server";
/** Whether the user may access the API: the API_ACCESSER role (includes supporters), or admin/organizer/streamer of an established tournament organization. */
export async function checkUserHasApiAccess(user: AuthenticatedUser) {
// NOTE: permissions logic also exists in ApiRepository.findAllApiTokens function
if (user.roles.includes("API_ACCESSER")) {
return true;
}
const orgs = await TournamentOrganizationRepository.findByUserId(user.id, {
roles: ["ADMIN", "ORGANIZER", "STREAMER"],
});
return orgs.some((org) => org.isEstablished);
}