Gate setup and admin navigation
This commit is contained in:
20
src/lib/setup.ts
Normal file
20
src/lib/setup.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user