essential/validation #604
Replies: 2 comments 5 replies
-
Can I use Zod for validation, since that's what the project is using Clent side already, or must I use t from Elysia? |
Beta Was this translation helpful? Give feedback.
4 replies
-
How can I have a response validator for 200 but keep the default for the other error codes? {
headers: headersValidator,
query: searchValidator,
response: {
200: getAllResponseValidator,
},
beforeHandle({ headers, status }) {
const apiKey = headers['x-api-key'];
if (!apiKey) {
return status(401);
}
const payload = jwtSigner.decode(apiKey);
if (payload.role !== 'admin') {
return status(403);
}
},
} For example, this wont work because, 401 and 403 just blow up errors. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
essential/validation
Schemas are strictly typed definitions, used to infer TypeScript's type and data validation of an incoming request and outgoing response. Elysia's schema validation is based on Sinclair's TypeBox, a TypeScript library for data validation.
https://elysiajs.com/essential/validation
Beta Was this translation helpful? Give feedback.
All reactions