-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathschema.ts
More file actions
37 lines (34 loc) · 1.37 KB
/
schema.ts
File metadata and controls
37 lines (34 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { z } from 'zod';
import { ACCOUNT_PASSWORD_MIN_LENGTH, ACCOUNT_PASSWORD_MIN_CHAR_TYPES } from '~/shared/constants';
import { Dictionary } from '~/shared/utils';
import { checkPassword } from '~/shared/utils/passwordValidation';
export const ChangePasswordSchema = z
.object({
old: z.string().min(1, { message: Dictionary.validation.password.required }),
new: z.string().superRefine((value, ctx) => {
const result = checkPassword(value);
if (!result.meetsLength)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: Dictionary.validation.password.minLength,
params: { chars: ACCOUNT_PASSWORD_MIN_LENGTH },
});
if (!result.hasNoSpaces)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: Dictionary.validation.password.blankSpaces,
});
if (!result.meetsCharTypeRequirement)
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: Dictionary.validation.password.characterTypes,
params: { types: ACCOUNT_PASSWORD_MIN_CHAR_TYPES },
});
}),
confirm: z.string().min(1, { message: Dictionary.validation.password.required }),
})
.refine((data) => data.new === data.confirm, {
message: Dictionary.validation.password.notMatch,
path: ['confirm'],
});
export type TChangePassword = z.infer<typeof ChangePasswordSchema>;