From d13975adac62e14cbb1dc59734200c9ab394b1bf Mon Sep 17 00:00:00 2001 From: HarikrishnanD Date: Tue, 16 Sep 2025 13:11:22 +0530 Subject: [PATCH 1/2] fix: add email validation to profile form to prevent empty values - Add email format and required validation to profile form schema - Add email validation to API schema and service layer - Improve error handling in user update mutation - Fixes issue where users could save empty email causing sign-in failures -#2613 --- .../dashboard/settings/profile/profile-form.tsx | 2 +- apps/dokploy/server/api/routers/user.ts | 10 +++++++++- packages/server/src/db/schema/user.ts | 1 + packages/server/src/services/user.ts | 13 +++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx b/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx index 7ac65f1b2..2f6d6793c 100644 --- a/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx +++ b/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx @@ -33,7 +33,7 @@ import { Disable2FA } from "./disable-2fa"; import { Enable2FA } from "./enable-2fa"; const profileSchema = z.object({ - email: z.string(), + email: z.string().email("Please enter a valid email address").min(1, "Email is required"), password: z.string().nullable(), currentPassword: z.string().nullable(), image: z.string().optional(), diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts index 2e7c7a0c5..362f97727 100644 --- a/apps/dokploy/server/api/routers/user.ts +++ b/apps/dokploy/server/api/routers/user.ts @@ -192,7 +192,15 @@ export const userRouter = createTRPCRouter({ }) .where(eq(account.userId, ctx.user.id)); } - return await updateUser(ctx.user.id, input); + + try { + return await updateUser(ctx.user.id, input); + } catch (error) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: error instanceof Error ? error.message : "Failed to update user", + }); + } }), getUserByToken: publicProcedure .input(apiFindOneToken) diff --git a/packages/server/src/db/schema/user.ts b/packages/server/src/db/schema/user.ts index 933a7490c..a26a8ccdd 100644 --- a/packages/server/src/db/schema/user.ts +++ b/packages/server/src/db/schema/user.ts @@ -322,6 +322,7 @@ export const apiUpdateWebServerMonitoring = z.object({ }); export const apiUpdateUser = createSchema.partial().extend({ + email: z.string().email("Please enter a valid email address").min(1, "Email is required").optional(), password: z.string().optional(), currentPassword: z.string().optional(), name: z.string().optional(), diff --git a/packages/server/src/services/user.ts b/packages/server/src/services/user.ts index 728d5b8ee..adfccd5b2 100644 --- a/packages/server/src/services/user.ts +++ b/packages/server/src/services/user.ts @@ -296,6 +296,19 @@ export const findMemberById = async ( }; export const updateUser = async (userId: string, userData: Partial) => { + // Validate email if it's being updated + if (userData.email !== undefined) { + if (!userData.email || userData.email.trim() === "") { + throw new Error("Email is required and cannot be empty"); + } + + // Basic email format validation + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + if (!emailRegex.test(userData.email)) { + throw new Error("Please enter a valid email address"); + } + } + const user = await db .update(users_temp) .set({ From c1896f88776d1b1d14801a77c58a3b6d829e2d6f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 16 Sep 2025 07:47:55 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- .../components/dashboard/settings/profile/profile-form.tsx | 5 ++++- apps/dokploy/server/api/routers/user.ts | 5 +++-- packages/server/src/db/schema/user.ts | 6 +++++- packages/server/src/services/user.ts | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx b/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx index 2f6d6793c..d040472d6 100644 --- a/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx +++ b/apps/dokploy/components/dashboard/settings/profile/profile-form.tsx @@ -33,7 +33,10 @@ import { Disable2FA } from "./disable-2fa"; import { Enable2FA } from "./enable-2fa"; const profileSchema = z.object({ - email: z.string().email("Please enter a valid email address").min(1, "Email is required"), + email: z + .string() + .email("Please enter a valid email address") + .min(1, "Email is required"), password: z.string().nullable(), currentPassword: z.string().nullable(), image: z.string().optional(), diff --git a/apps/dokploy/server/api/routers/user.ts b/apps/dokploy/server/api/routers/user.ts index 362f97727..d30b99b3a 100644 --- a/apps/dokploy/server/api/routers/user.ts +++ b/apps/dokploy/server/api/routers/user.ts @@ -192,13 +192,14 @@ export const userRouter = createTRPCRouter({ }) .where(eq(account.userId, ctx.user.id)); } - + try { return await updateUser(ctx.user.id, input); } catch (error) { throw new TRPCError({ code: "BAD_REQUEST", - message: error instanceof Error ? error.message : "Failed to update user", + message: + error instanceof Error ? error.message : "Failed to update user", }); } }), diff --git a/packages/server/src/db/schema/user.ts b/packages/server/src/db/schema/user.ts index a26a8ccdd..ca92f50e8 100644 --- a/packages/server/src/db/schema/user.ts +++ b/packages/server/src/db/schema/user.ts @@ -322,7 +322,11 @@ export const apiUpdateWebServerMonitoring = z.object({ }); export const apiUpdateUser = createSchema.partial().extend({ - email: z.string().email("Please enter a valid email address").min(1, "Email is required").optional(), + email: z + .string() + .email("Please enter a valid email address") + .min(1, "Email is required") + .optional(), password: z.string().optional(), currentPassword: z.string().optional(), name: z.string().optional(), diff --git a/packages/server/src/services/user.ts b/packages/server/src/services/user.ts index adfccd5b2..ae03432a1 100644 --- a/packages/server/src/services/user.ts +++ b/packages/server/src/services/user.ts @@ -301,7 +301,7 @@ export const updateUser = async (userId: string, userData: Partial) => { if (!userData.email || userData.email.trim() === "") { throw new Error("Email is required and cannot be empty"); } - + // Basic email format validation const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(userData.email)) {