-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
500 Received an instance of URLSearchParams #883
Comments
Likely the same issue as #479. Seems to be caused in this part of nuxt-auth/src/runtime/composables/authjs/useAuth.ts Lines 121 to 133 in ae2bf09
|
@Invisi Yes exactly, that is the initial point then server tries to parse the body and throws an exception. |
I experience the same error, I am not able to log out of my application at the moment. Could you maybe treat this bug as a high prio one? |
Hi @alimozdemir @Dunowen, I need to confirm why are we providing search params as body. This seemed to work so far, but apparently something changed in one of our dependencies ( |
Is there any update on this? |
After some investigation, I can confirm that this is a bug with |
@phoenix-ru that's why I tested h3 individually for URLSearchParams in a simple code. But it was ok, it was working |
@alimozdemir Yes, I also tested it individually and I will try to create a very minimal reproduction without |
I didn't know what _fetch had internal approach, although good information. Thank you for the headsup |
Providing an update: I tested the Nuxt starter template and it consistently reproduces there. The only issue is that it seems to be changed in more recent versions of Good news is that it seems to be finally patched in their |
@phoenix-ru I am happy to hear that and hoping it will happen fast causing my app not to run in the production environment. I getting a 500 error saying Invalid URL. |
I don't think it is going to be happening soon, could we have a workaround for this? e.g. disable _fetch internal approach for this call explicitly? main branch pointing for v2, and it is not clear yet when it is going to be ready. The last release was on Jun 20, even so, nuxt still uses 1.x version |
Does anyone have a workaround? I can't run it in production environment, error 500. |
You are right about it - I also considered patching this until a new upd: It happens on a plain Nuxt server without our module. I will have to create a bug report to upd2: Okay, I managed to patch [1] ERROR [nuxt] [request error] [unhandled] [500] The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of URLSearchParams
at Function.from (node:buffer:319:9)
at ./node_modules/h3/dist/index.mjs:410:21
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.start (./node_modules/h3/dist/index.mjs:486:26) |
PR created inside |
To work I'm change this code in the build Path: let body;
try {
body = isMethod(event, ["PATCH", "POST", "PUT", "DELETE"]) ? await readBody(event) : void 0;
}catch(err){} |
Environment
Darwin
v20.11.1
3.12.4
3.13.0
2.9.7
pnpm@8.15.4
-
modules
,extends
,future
,css
,app
,runtimeConfig
,auth
,compatibilityDate
@nuxtjs/tailwindcss@6.12.1
,@nuxt/fonts@0.7.2
,@vueuse/nuxt@10.11.1
,@sidebase/nuxt-auth@0.8.2
-
Reproduction
It is hard to reproduce this error without sharing the secrets. But I did a debugging with loading nuxt-auth package directly from the source. I will describe all findings.
Describe the bug
First of all I would like to share my handler file.
Whenever I login or logout I receive following exception
[500] The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of URLSearchParams
error on
nuxt-auth/src/runtime/server/services/authjs/nuxtAuthHandler.ts
Line 206 in c5a62d9
somehow, h3 package readBody throws this error, but I already test that readBody function with URLSearchParams object in a clean project and it is working ok.
The only thing that I found is
https://github.com/unjs/h3/blob/853ae882b58927bbc8eed41b9c02fa7efc529192/src/utils/body.ts#L47
this
_rawBody
variable is empty on simple tests in a sandbox, but when nuxt-auth sends URLSearchParams object, it is filled. In my sandbox tests, it's not hitting the next if condition and does not throw the error onhttps://github.com/unjs/h3/blob/853ae882b58927bbc8eed41b9c02fa7efc529192/src/utils/body.ts#L93
Additional context
No response
Logs
ERROR [nuxt] [request error] [unhandled] [500] The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received an instance of URLSearchParams at Function.from (node:buffer:324:9) at ./node_modules/.pnpm/h3@1.12.0/node_modules/h3/dist/index.mjs:410:21 at async readBody (./node_modules/.pnpm/h3@1.12.0/node_modules/h3/dist/index.mjs:438:16) at readBodyForNext (./node_modules/.pnpm/@sidebase+nuxt-auth@0.8.2_magicast@0.3.4_next-auth@4.21.1_next@13.5.6_@babel+core@7.25.2_reac_wqxp7nydnxshx7noobpzq4kbim/node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs:18:12) at getInternalNextAuthRequestData (./node_modules/.pnpm/@sidebase+nuxt-auth@0.8.2_magicast@0.3.4_next-auth@4.21.1_next@13.5.6_@babel+core@7.25.2_reac_wqxp7nydnxshx7noobpzq4kbim/node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs:75:18) at Object.handler (./node_modules/.pnpm/@sidebase+nuxt-auth@0.8.2_magicast@0.3.4_next-auth@4.21.1_next@13.5.6_@babel+core@7.25.2_reac_wqxp7nydnxshx7noobpzq4kbim/node_modules/@sidebase/nuxt-auth/dist/runtime/server/services/authjs/nuxtAuthHandler.mjs:87:25) at async ./node_modules/.pnpm/h3@1.12.0/node_modules/h3/dist/index.mjs:1975:19 at async Object.callAsync (./node_modules/.pnpm/unctx@2.3.1/node_modules/unctx/dist/index.mjs:72:16) at async toNodeHandle (./node_modules/.pnpm/h3@1.12.0/node_modules/h3/dist/index.mjs:2266:7) at async ufetch (./node_modules/.pnpm/unenv@1.10.0/node_modules/unenv/runtime/fetch/index.mjs:9:17)
The text was updated successfully, but these errors were encountered: