Skip to content

Commit

Permalink
docs: Simplify Zod example (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn authored Jan 16, 2025
1 parent 8a90489 commit 03d48f4
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Note that when you're displaying messages generated in Server Actions to the use
```tsx
import {getTranslations} from 'next-intl/server';
import {loginUser} from '@/services/session';
import {isEqual} from 'lodash';
import {z} from 'zod';

const loginFormSchema = z.object({
Expand All @@ -87,13 +86,12 @@ async function loginAction(data: FormData) {
})
.safeParseAsync(values, {
errorMap(issue, ctx) {
let message;
const path = issue.path.join('.');

if (isEqual(issue.path, ['email'])) {
message = t('invalidEmail');
} else if (isEqual(issue.path, ['password'])) {
message = t('invalidPassword');
}
const message = {
email: t('invalidEmail')
password: t('invalidPassword')
}[path];

return {message: message || ctx.defaultError};
}
Expand Down

0 comments on commit 03d48f4

Please sign in to comment.