Sean Cassiere
Sean Cassiere
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Sean Cassiere on 9/20/2022 in #questions
Creating Zod Input Validation Error after tRPC entry
I've got a ct3a project, with all the bells and whistles (including tRPC and zod). In addition, on the frontend part of the app I've set up a couple of forms with react-hook-form, and I am sharing the zod schemas being used with tRPC. What I'm looking to achieve, is AFTER the input validation by the tRPC router mutation has been completed, and the code has moved on into the logic within the mutation itself, to be able to send back an input validation error and set these errors in react-hook-form. This would be the business logic: 1. User begins registration flow. 2. User enters their email and username along with other fields. 3. React-hook-form uses a shared schema (with tRPC) to validate items such as minLength, isEmail, regex for special characters, etc. 4. User submits valid the form-data to tRPC via a mutation. 5. tRPC accepts and validates the incoming input (since the same schema is being shared on the frontend). 6. In the mutation, the username field is checked in the database to find if it already exists. 7. If username already exists, a BAD_REQUEST error (or something equivalent in the 400 range) would be sent back to frontend, which then can be inserted into react-hook-form. P.S. I have no clue if this (https://trpc.io/docs/v9/error-formatting#all-properties-sent-to-formaterror) plays into what I'm looking for.
64 replies
TTCTheo's Typesafe Cult
Created by Sean Cassiere on 9/20/2022 in #questions
Help - session type in _app.tsx is missing
24 replies