@@ -43,31 +43,29 @@ function createSchema(
4343 . string ( { required_error : "You must enter a name" } )
4444 . min ( 2 , "Your name must be at least 2 characters long" )
4545 . max ( 50 ) ,
46- email : emailSchema . superRefine ( ( email , ctx ) => {
47- if ( email . length > MAX_EMAIL_LENGTH ) {
48- return ;
49- }
50-
51- if ( constraints . isEmailUnique === undefined ) {
52- //client-side validation skips this
53- ctx . addIssue ( {
54- code : z . ZodIssueCode . custom ,
55- message : conformZodMessage . VALIDATION_UNDEFINED ,
56- } ) ;
57- } else {
58- // Tell zod this is an async validation by returning the promise
59- return constraints . isEmailUnique ( email ) . then ( ( isUnique ) => {
60- if ( isUnique ) {
61- return ;
62- }
63-
46+ email : emailSchema . pipe (
47+ z . string ( ) . superRefine ( ( email , ctx ) => {
48+ if ( constraints . isEmailUnique === undefined ) {
49+ //client-side validation skips this
6450 ctx . addIssue ( {
6551 code : z . ZodIssueCode . custom ,
66- message : "Email is already being used by a different account" ,
52+ message : conformZodMessage . VALIDATION_UNDEFINED ,
6753 } ) ;
68- } ) ;
69- }
70- } ) ,
54+ } else {
55+ // Tell zod this is an async validation by returning the promise
56+ return constraints . isEmailUnique ( email ) . then ( ( isUnique ) => {
57+ if ( isUnique ) {
58+ return ;
59+ }
60+
61+ ctx . addIssue ( {
62+ code : z . ZodIssueCode . custom ,
63+ message : "Email is already being used by a different account" ,
64+ } ) ;
65+ } ) ;
66+ }
67+ } )
68+ ) ,
7169 marketingEmails : z . preprocess ( ( value ) => value === "on" , z . boolean ( ) ) ,
7270 } ) ;
7371}
0 commit comments