Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.superRefine should have some information about previous errors #3870

Open
Codename-404 opened this issue Nov 25, 2024 · 0 comments
Open

.superRefine should have some information about previous errors #3870

Codename-404 opened this issue Nov 25, 2024 · 0 comments

Comments

@Codename-404
Copy link

Codename-404 commented Nov 25, 2024

Hi, so most of the time we don't want to run refine or superRefine if any previous condition has errors. To control this behaviour, there should be a way to at least get if there are any previous errors. Then we can return a fatal error from superRefine.
Otherwise such as in the case below, I will have to call the api even when I could simple prevent it for not having appropriate data.
This can be checking if email already exists in the database, we must know if the fields which can be checked offline are error free, only then we will call api, which will reduce load on server, also faster feedback to users, otherwise users will have to wait for api everytime they clicks submit even when there is no need (eg: when there are errors with fields that can be checked offline)

`
const formSchema = z
.object({
email: z.string().email({ message: "Please enter a valid email" }),
password: z
.string()
.min(8, { message: "Password must be at least 8 characters" })
.max(16, { message: "Password must be at most 16 characters" }),
})
.superRefine(async (data, ctx) => {
const { success, message, status } = await validateLogin(
data.email,
data.password
);

if (!success) {
  ctx.addIssue({
    path: ["email"],
    code: z.ZodIssueCode.custom,
    message: message || "Failed to login, try again",
  });
}

});
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant