5 changed files with 40 additions and 31 deletions
@ -0,0 +1,23 @@ |
|||||
|
import { z } from 'zod' |
||||
|
|
||||
|
export const registerSchema = z |
||||
|
.object({ |
||||
|
username: z |
||||
|
.string() |
||||
|
.trim() |
||||
|
.min(3, '用户名至少需要3个字符') |
||||
|
.max(30, '用户名最多30个字符'), |
||||
|
password: z.string().min(8, '密码至少需要8个字符'), |
||||
|
confirmPassword: z.string(), |
||||
|
captchaToken: z.string().min(1, '验证码令牌不能为空'), |
||||
|
captchaText: z.string().min(1, '验证码不能为空'), |
||||
|
}) |
||||
|
.refine((data) => data.password === data.confirmPassword, { |
||||
|
message: '两次输入的密码不一致', |
||||
|
path: ['confirmPassword'], |
||||
|
}) |
||||
|
|
||||
|
/** Client-side schema: omits captchaToken (managed by page shell) */ |
||||
|
export const clientRegisterSchema = registerSchema.omit({ captchaToken: true }) |
||||
|
|
||||
|
export type RegisterInput = z.infer<typeof clientRegisterSchema> |
||||
@ -0,0 +1,5 @@ |
|||||
|
{ |
||||
|
"name": "shared", |
||||
|
"type": "module", |
||||
|
"private": true |
||||
|
} |
||||
@ -1,18 +1 @@ |
|||||
import { z } from 'zod' |
export { registerSchema } from 'shared/auth-schema' |
||||
|
|
||||
export const registerSchema = z |
|
||||
.object({ |
|
||||
username: z |
|
||||
.string() |
|
||||
.trim() |
|
||||
.min(3, '用户名至少需要3个字符') |
|
||||
.max(30, '用户名最多30个字符'), |
|
||||
password: z.string().min(8, '密码至少需要8个字符'), |
|
||||
confirmPassword: z.string(), |
|
||||
captchaToken: z.string().min(1, '验证码令牌不能为空'), |
|
||||
captchaText: z.string().min(1, '验证码不能为空'), |
|
||||
}) |
|
||||
.refine((data) => data.password === data.confirmPassword, { |
|
||||
message: '两次输入的密码不一致', |
|
||||
path: ['confirmPassword'], |
|
||||
}) |
|
||||
|
|||||
Loading…
Reference in new issue