21 lines
433 B
TypeScript
21 lines
433 B
TypeScript
import { redirect } from "next/navigation";
|
|
import { prisma } from "./prisma";
|
|
|
|
export async function hasAdminUser() {
|
|
try {
|
|
const admin = await prisma.userRole.findFirst({
|
|
where: { role: { name: "admin" } },
|
|
select: { userId: true }
|
|
});
|
|
return Boolean(admin);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function requireInitialSetup() {
|
|
if (!(await hasAdminUser())) {
|
|
redirect("/setup");
|
|
}
|
|
}
|