feat(auth): assign ADMIN role to the first user on sign up

This commit is contained in:
cfngc4594 2025-03-18 21:53:59 +08:00
parent e25a97d698
commit 63c0656f25

View File

@ -17,12 +17,20 @@ export async function signUpWithCredentials(formData: { email: string; password:
const pwHash = await bcrypt.hash(validatedData.password, saltRounds); const pwHash = await bcrypt.hash(validatedData.password, saltRounds);
await prisma.user.create({ const user = await prisma.user.create({
data: { data: {
email: validatedData.email, email: validatedData.email,
password: pwHash, password: pwHash,
}, },
}); });
const count = await prisma.user.count();
if (count === 1) {
await prisma.user.update({
where: { id: user.id },
data: { role: "ADMIN" },
});
}
redirect("/sign-in"); redirect("/sign-in");
} }