fix: email-address with apostrophe not accepted (#15535)
Co-authored-by: Keith Williams <[email protected]> Co-authored-by: Omar López <[email protected]> Co-authored-by: Amit Sharma <[email protected]>
This commit is contained in:
27 files changed
+77
-42
No files matched your search
@@ -202,7 +202,7 @@ model DestinationCalendar {
|
||||
id Int @id @default(autoincrement())
|
||||
integration String
|
||||
externalId String
|
||||
/// @zod.email()
|
||||
/// @zod.custom(imports.emailSchema)
|
||||
primaryEmail String?
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int? @unique
|
||||
@@ -247,7 +247,7 @@ model User {
|
||||
id Int @id @default(autoincrement())
|
||||
username String?
|
||||
name String?
|
||||
/// @zod.email()
|
||||
/// @zod.custom(imports.emailSchema)
|
||||
email String
|
||||
emailVerified DateTime?
|
||||
password UserPassword?
|
||||
@@ -578,7 +578,7 @@ model Booking {
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
userId Int?
|
||||
// User's email at the time of booking
|
||||
/// @zod.email()
|
||||
/// @zod.custom(imports.emailSchema)
|
||||
userPrimaryEmail String?
|
||||
references BookingReference[]
|
||||
eventType EventType? @relation(fields: [eventTypeId], references: [id])
|
||||
|
||||
@@ -18,6 +18,7 @@ import { isPasswordValid } from "@calcom/features/auth/lib/isPasswordValid";
|
||||
import type { FieldType as FormBuilderFieldType } from "@calcom/features/form-builder/schema";
|
||||
import { fieldsSchema as formBuilderFieldsSchema } from "@calcom/features/form-builder/schema";
|
||||
import { isSupportedTimeZone } from "@calcom/lib/date-fns";
|
||||
import { emailSchema as emailRegexSchema, emailRegex } from "@calcom/lib/emailSchema";
|
||||
import { slugify } from "@calcom/lib/slugify";
|
||||
import { EventTypeCustomInputType } from "@calcom/prisma/enums";
|
||||
|
||||
@@ -699,11 +700,12 @@ export const unlockedManagedEventTypeProps = {
|
||||
destinationCalendar: allManagedEventTypeProps.destinationCalendar,
|
||||
};
|
||||
|
||||
export const emailSchema = emailRegexSchema;
|
||||
|
||||
// The PR at https://github.com/colinhacks/zod/pull/2157 addresses this issue and improves email validation
|
||||
// I introduced this refinement(to be used with z.email()) as a short term solution until we upgrade to a zod
|
||||
// version that will include updates in the above PR.
|
||||
export const emailSchemaRefinement = (value: string) => {
|
||||
const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;
|
||||
return emailRegex.test(value);
|
||||
};
|
||||
|
||||
@@ -711,7 +713,7 @@ export const signupSchema = z.object({
|
||||
// Username is marked optional here because it's requirement depends on if it's the Organization invite or a team invite which isn't easily done in zod
|
||||
// It's better handled beyond zod in `validateAndGetCorrectedUsernameAndEmail`
|
||||
username: z.string().optional(),
|
||||
email: z.string().email({ message: "Invalid email" }),
|
||||
email: z.string().regex(emailRegex, { message: "Invalid email" }),
|
||||
password: z.string().superRefine((data, ctx) => {
|
||||
const isStrict = false;
|
||||
const result = isPasswordValid(data, true, isStrict);
|
||||
@@ -730,7 +732,7 @@ export const signupSchema = z.object({
|
||||
});
|
||||
|
||||
export const ZVerifyCodeInputSchema = z.object({
|
||||
email: z.string().email(),
|
||||
email: emailSchema,
|
||||
code: z.string(),
|
||||
});
|
||||
|
||||
@@ -743,4 +745,4 @@ export const getStringAsNumberRequiredSchema = (t: TFunction) =>
|
||||
export const bookingSeatDataSchema = z.object({
|
||||
description: z.string().optional(),
|
||||
responses: bookingResponses,
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user