feat(auth): add event to assign ADMIN role to the first user

This commit is contained in:
cfngc4594 2025-03-18 21:53:12 +08:00
parent b55ed07004
commit e25a97d698

View File

@ -87,4 +87,15 @@ export const { auth, handlers, signIn, signOut } = NextAuth({
return encode(params); // Default encoding for JWT
},
},
events: {
async createUser({ user }) {
const count = await prisma.user.count();
if (count === 1) {
await prisma.user.update({
where: { id: user.id },
data: { role: "ADMIN" },
});
}
},
},
});