-
-
Notifications
You must be signed in to change notification settings - Fork 836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
conflicting validated input values when piping data through middleware validators with differing schemas #3783
Comments
This has to do with how each library handles the result of the Since TanStack Start (and Router) interface with these validation libraries using Standard Schema, we're only accessing the equivalent Diving deeper into these libraries, this is what I found out about them when piping in data that was in the original schema alongside valid input.
This diverging behaviour across the libraries presents a problem as TanStack Start (and Router) do not interface with these libraries directly, rather using the Standard Schema interface to access the We should add a callout in the documentation about the user understanding how their validation library of choice behaves with his type of parsing data through multiple schemas. At the moment, I'm not too sure if there are actual fixes we can apply that would fix the behaviour of these upstream libraries. |
As mentioned above, this makes it a bit tricky to come up with a solution to this. These are the approaches that I've come up with so far, 1 - Perform a shallow merge on the
|
Which project does this relate to?
Start
Describe the bug
The output of zod parsing removes any extra keys from the data input and means that any subsequent validators cannot successfully validate the body. This can be worked around by putting
.passthrough()
at the end of the zod schema. The types for calling the serverFn imply that this is not the case as it has the inputs merged for the data field.Your Example Website or App
https://codesandbox.io/p/devbox/sleepy-rubin-9qd7w2
Steps to Reproduce the Bug or Issue
Run
pnpm dev
Navigate to the home page.
Expected behavior
As a user I would expect that I am able to validate input on the middleware, but then also be able to validate additional inputs on the serverFn, for example if I need to validate that a user can access an organisation, i would put the organisation id in the middleware, validate that they can access it and put the organisation into the context, then validate the serverFn specific inputs in the serverFn. This assumption is backed up by how the types get merged by the middleware and the serverFn.
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: