Skip to content

Commit

Permalink
docs: Simplify zod example
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed Jan 30, 2025
1 parent 290cb60 commit 190ee1e
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,18 @@ async function loginAction(data: FormData) {
const t = await getTranslations('LoginForm');
const values = Object.fromEntries(data);

const result = await loginFormSchema
.refine(async (credentials) => loginUser(credentials), {
message: t('invalidCredentials')
})
.safeParseAsync(values, {
errorMap(issue, ctx) {
const path = issue.path.join('.');

const message = {
email: t('invalidEmail')
password: t('invalidPassword')
}[path];

return {message: message || ctx.defaultError};
}
});
const result = loginFormSchema.safeParse(values, {
errorMap(issue, ctx) {
const path = issue.path.join('.');

const message = {
email: t('invalidEmail')
password: t('invalidPassword')
}[path];

return {message: message || ctx.defaultError};
}
});

// ...
}
Expand Down

0 comments on commit 190ee1e

Please sign in to comment.