@@ -27,6 +27,7 @@ import { useUser } from "~/hooks/useUser";
2727import { redirectWithSuccessMessage } from "~/models/message.server" ;
2828import { updateUser } from "~/models/user.server" ;
2929import { requireUserId } from "~/services/session.server" ;
30+ import { emailSchema , MAX_EMAIL_LENGTH } from "~/utils/emailValidation" ;
3031import { rootPath } from "~/utils/pathBuilder" ;
3132import { getVercelInstallParams } from "~/v3/vercel" ;
3233
@@ -72,29 +73,30 @@ function createSchema(
7273 return z
7374 . object ( {
7475 name : z . string ( ) . min ( 3 , "Your name must be at least 3 characters" ) . max ( 50 ) ,
75- email : z
76- . string ( )
77- . email ( )
78- . superRefine ( ( email , ctx ) => {
79- if ( constraints . isEmailUnique === undefined ) {
76+ email : emailSchema . superRefine ( ( email , ctx ) => {
77+ if ( email . length > MAX_EMAIL_LENGTH ) {
78+ return ;
79+ }
80+
81+ if ( constraints . isEmailUnique === undefined ) {
82+ ctx . addIssue ( {
83+ code : z . ZodIssueCode . custom ,
84+ message : conformZodMessage . VALIDATION_UNDEFINED ,
85+ } ) ;
86+ } else {
87+ return constraints . isEmailUnique ( email ) . then ( ( isUnique ) => {
88+ if ( isUnique ) {
89+ return ;
90+ }
91+
8092 ctx . addIssue ( {
8193 code : z . ZodIssueCode . custom ,
82- message : conformZodMessage . VALIDATION_UNDEFINED ,
83- } ) ;
84- } else {
85- return constraints . isEmailUnique ( email ) . then ( ( isUnique ) => {
86- if ( isUnique ) {
87- return ;
88- }
89-
90- ctx . addIssue ( {
91- code : z . ZodIssueCode . custom ,
92- message : "Email is already being used by a different account" ,
93- } ) ;
94+ message : "Email is already being used by a different account" ,
9495 } ) ;
95- }
96- } ) ,
97- confirmEmail : z . string ( ) ,
96+ } ) ;
97+ }
98+ } ) ,
99+ confirmEmail : emailSchema ,
98100 referralSource : z . string ( ) . optional ( ) ,
99101 referralSourceOther : z . string ( ) . optional ( ) ,
100102 role : z . string ( ) . optional ( ) ,
@@ -290,6 +292,7 @@ export default function Page() {
290292 </ Label >
291293 < Input
292294 { ...getInputProps ( email , { type : "email" } ) }
295+ maxLength = { MAX_EMAIL_LENGTH }
293296 defaultValue = { enteredEmail }
294297 onChange = { ( e ) => {
295298 setEnteredEmail ( e . target . value ) ;
@@ -306,6 +309,7 @@ export default function Page() {
306309 < Label htmlFor = { confirmEmail . id } > Confirm email</ Label >
307310 < Input
308311 { ...getInputProps ( confirmEmail , { type : "email" } ) }
312+ maxLength = { MAX_EMAIL_LENGTH }
309313 placeholder = "Your email, again"
310314 icon = { EnvelopeIcon }
311315 spellCheck = { false }
0 commit comments