Complete all for Items
This commit is contained in:
@@ -1,19 +1,16 @@
|
||||
import { z } from "zod"
|
||||
|
||||
// Treats null/undefined as missing so validation surfaces one clear
|
||||
// "required" message instead of a generic type error.
|
||||
// Plain z.string(), not z.preprocess(): preprocess widens the schema's INPUT type to
|
||||
// `unknown`, so zodResolver produced a Resolver<{email: unknown, …}> that could not be
|
||||
// assigned to useForm<LoginValues> — the long-standing type error on the login page.
|
||||
// Form fields always yield strings (RHF defaults them to ""), so the null/undefined
|
||||
// coercion it was guarding against cannot occur here.
|
||||
function requiredString(message: string) {
|
||||
return z.preprocess(
|
||||
(val) => (val === null || val === undefined ? "" : val),
|
||||
z.string().min(1, message)
|
||||
)
|
||||
return z.string().min(1, message)
|
||||
}
|
||||
|
||||
// Email validation schema
|
||||
export const emailSchema = z.preprocess(
|
||||
(val) => (val === null || val === undefined ? "" : val),
|
||||
z.string().min(1, "Email is required").email("Enter a valid email")
|
||||
)
|
||||
export const emailSchema = z.string().min(1, "Email is required").email("Enter a valid email")
|
||||
|
||||
// Login schema (email + password) for reuse across the app
|
||||
export const loginSchema = z.object({
|
||||
|
||||
Reference in New Issue
Block a user