mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
feat(auth): assign ADMIN role to the first user on sign up
This commit is contained in:
parent
e25a97d698
commit
63c0656f25
@ -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");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user