You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to validate a form with an async request to a server route that works fine when tested on its own, however, in the zod validation always returns false.
I am trying to prevent user from attempting to register with an email that has already been taken, and so validating email inside a nuxtui form by calling this async server route.
testing the server route works just fine and return expected true or false http://localhost:3000/user/is_email_available?email=er.ttt@gmail.com returns true or false as expected
but for some reason always returns false in the zod schema validation.
const schema = z.object({
tenant_name: z.string({ required_error: "Business Name is required" }).
min(2, { message: "Must be at least 2 characters" }).
refine(async (val) => await tenantSlugAvailable(slugify(val)), (val) => ({ message: `${val} is not available` })),
email: z.string({ required_error: "Business Email is required" }).email({ message: "Invalid email address" }).
refine(async (val) => { await useFetch('user/is_email_available', { query: { email: val } }) }, (val) => ({ message: `${val} is not available` })),
password: z.string({ required_error: "Password is required" }).min(8, { message: 'Must be at least 8 characters' }),
confirmPassword: z.string({ required_error: "Password Confirmation is required" }).min(8, { message: 'Must be at least 8 characters' })
}).refine((values) => values.password === values.confirmPassword,
{
message: "Passwords must match!",
path: ["confirmPassword"],
}
);
Please can someone take a look and show me what I am doing wrong? have spent a day on this already and not making any headway.
Thanks
The text was updated successfully, but these errors were encountered:
Hello,
I am trying to validate a form with an async request to a server route that works fine when tested on its own, however, in the zod validation always returns false.
I am trying to prevent user from attempting to register with an email that has already been taken, and so validating email inside a nuxtui form by calling this async server route.
testing the server route works just fine and return expected true or false
http://localhost:3000/user/is_email_available?email=er.ttt@gmail.com
returns true or false as expectedbut for some reason always returns false in the zod schema validation.
Please can someone take a look and show me what I am doing wrong? have spent a day on this already and not making any headway.
Thanks
The text was updated successfully, but these errors were encountered: