Skip to content
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

get validated data with yup is failing #725

Open
edimitchel opened this issue Mar 31, 2024 · 1 comment
Open

get validated data with yup is failing #725

edimitchel opened this issue Mar 31, 2024 · 1 comment

Comments

@edimitchel
Copy link
Contributor

Environment


  • Operating System: Darwin
  • Node Version: v20.11.1
  • Nuxt Version: 3.11.1
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.4
  • Package Manager: pnpm@8.15.5
  • Builder: -
  • User Config: ssr, devtools, modules, primevue, experimental, css, app, eslint
  • Runtime Modules: @unocss/nuxt@0.58.8, @nuxt/eslint@0.3.0-beta.7, nuxt-primevue@0.3.1, @nuxtjs/supabase@1.2.0, @vueuse/nuxt@10.9.0, @pinia/nuxt@0.5.1
  • 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

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": {}
}
@edimitchel
Copy link
Contributor Author

Ok, it looks like an issue from yup, when I tried body => newSaleSchema.validate(body), it works. Probably an issue about context loss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant