fix: Handle existing user when editing profile

This commit is contained in:
Thomas Camlong committed 2024-05-10 15:24:40 +02:00
1 parent f5d71aebb4
commit 6e2bd0ce11
2 files changed
+39 -5

No files matched your search

+9
View File
@@ -90,7 +90,16 @@ export const userRouter = createTRPCRouter({
.from(users)
.where(eq(users.id, input.userId))
.limit(1);
const existingUser = await ctx.db.query.users.findFirst({
where: eq(users.name, input.form.name),
});
if (existingUser !== undefined) {
throw new TRPCError({
code: "FORBIDDEN",
message: `User ${input.form.name} already exists`,
});
}
const emailDirty =
input.form.email && user[0]?.email !== input.form.email;
await ctx.db