mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-19 01:34:27 -05:00
17 lines
758 B
TypeScript
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);
|
|
}
|