All files / src/lib admin-role.ts

10% Statements 1/10
100% Branches 0/0
0% Functions 0/1
10% Lines 1/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 141x                          
import { AppError } from "@ontrack/backend-common";
import { prisma } from "./prisma.js";
 
/** Бросает 403, если у пользователя нет роли admin. */
export async function assertAdmin(uid: string): Promise<void> {
  const me = await prisma.userProfile.findUnique({
    where: { firebaseUid: uid },
    select: { role: true },
  });
  if (me?.role !== "admin") {
    throw new AppError(403, "FORBIDDEN", "Только для администратора");
  }
}