mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-21 11:28:47 +00:00
Merge pull request #2614 from Harikrishnan1367709/Profile-email-field-accepts-empty-values-causing-sign-in-issues-#2613
Fix profile email validation to prevent empty values causing sign-in issues-#2613
This commit is contained in:
@@ -33,7 +33,10 @@ import { Disable2FA } from "./disable-2fa";
|
|||||||
import { Enable2FA } from "./enable-2fa";
|
import { Enable2FA } from "./enable-2fa";
|
||||||
|
|
||||||
const profileSchema = z.object({
|
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(),
|
password: z.string().nullable(),
|
||||||
currentPassword: z.string().nullable(),
|
currentPassword: z.string().nullable(),
|
||||||
image: z.string().optional(),
|
image: z.string().optional(),
|
||||||
|
|||||||
@@ -192,7 +192,16 @@ export const userRouter = createTRPCRouter({
|
|||||||
})
|
})
|
||||||
.where(eq(account.userId, ctx.user.id));
|
.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
|
getUserByToken: publicProcedure
|
||||||
.input(apiFindOneToken)
|
.input(apiFindOneToken)
|
||||||
|
|||||||
@@ -322,6 +322,11 @@ export const apiUpdateWebServerMonitoring = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const apiUpdateUser = createSchema.partial().extend({
|
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(),
|
password: z.string().optional(),
|
||||||
currentPassword: z.string().optional(),
|
currentPassword: z.string().optional(),
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
|
|||||||
@@ -296,6 +296,19 @@ export const findMemberById = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const updateUser = async (userId: string, userData: Partial<User>) => {
|
export const updateUser = async (userId: string, userData: Partial<User>) => {
|
||||||
|
// 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
|
const user = await db
|
||||||
.update(users_temp)
|
.update(users_temp)
|
||||||
.set({
|
.set({
|
||||||
|
|||||||
Reference in New Issue
Block a user