Closed edimitchel closed 3 months ago
https://stackblitz.com/edit/nuxt-starter-cmsqm4?file=server%2Fapi%2Ftest.post.ts
Open Nuxt devtools, open Server routes, run the test api.
As suggested at https://h3.unjs.io/utils/request#readvalidatedbodyevent-validate, such library like zod can validate content from user data. As yup is such a zod library, I thought it would work like zod, but it doesn't..
No response
My logs on local is a quite different { "url": "/api/sale", "statusCode": 400, "statusMessage": "Validation Error", "message": "Cannot read properties of undefined (reading 'resolve')", "stack": "<pre><span class=\"stack internal\">at createError (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:79:15)</span>\n<span class=\"stack internal\">at createValidationError (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:245:9)</span>\n<span class=\"stack internal\">at validateData (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:241:11)</span>\n<span class=\"stack internal\">at readValidatedBody (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:455:10)</span>\n<span class=\"stack internal\">at process.processTicksAndRejections (node:internal/process/task_queues:95:5)</span>\n<span class=\"stack\">at Object.handler (./server/api/sale.post.ts:23:1)</span>\n<span class=\"stack internal\">at async ./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:1962:19</span>\n<span class=\"stack internal\">at async Object.callAsync (./node_modules/.pnpm/unctx@2.3.1/node_modules/unctx/dist/index.mjs:72:16)</span>\n<span class=\"stack internal\">at async Server.toNodeHandle (./node_modules/.pnpm/h3@1.11.1/node_modules/h3/dist/index.mjs:2249:7)</span></pre>", "data": {} }
Ok, it looks like an issue from yup, when I tried body => newSaleSchema.validate(body), it works. Probably an issue about context loss.
body => newSaleSchema.validate(body)
Environment
Build Modules: -
Reproduction
https://stackblitz.com/edit/nuxt-starter-cmsqm4?file=server%2Fapi%2Ftest.post.ts
Open Nuxt devtools, open Server routes, run the test api.
Describe the bug
As suggested at https://h3.unjs.io/utils/request#readvalidatedbodyevent-validate, such library like zod can validate content from user data. As yup is such a zod library, I thought it would work like zod, but it doesn't..
Additional context
No response
Logs