MarM
tRPC3y ago
3 replies
Mar

how to handle error from Zod in trpc?

I would like to return error instead throwing it away so i could show user nice feedback
i found https://zod.dev/?id=safeparse

but i dont know how to implement it

  signup: authProcedure
    .input(SignupInput)
    .mutation(
      async ({
        ctx: { supabase },
        input: { email, password, repeatPassword },
      }) => {
        const user = await supabase.auth.getSession()
        console.log(user.data.session)
        console.log(email, password, repeatPassword)
      }
    ),


export const SignupInput = z
  .object({
    password: z.string().min(8),
    repeatPassword: z.string().min(8),
  })
  .refine(data => data.password === data.repeatPassword, {
    message: "Passwords don't match",
    path: ['repeatPassword'],
  })
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
Was this page helpful?