Users of @sidebase/nuxt-auth are experiencing the following problem with our module, described here:
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
It works well when being called using HTTP, but fails when calling Nuxt endpoints from within a server. As you know,$fetch calls are translated to function calls in server code.
Environment
Linux
v22.5.1
3.13.2
3.13.2
2.9.7
npm@10.8.2
-
compatibilityDate
,devtools
-
-
Reproduction
https://github.com/phoenix-ru/h3-urlsearchparams-reproduction
Describe the bug
Users of
@sidebase/nuxt-auth
are experiencing the following problem with our module, described here:We managed to pinpoint the problem to this piece of code: https://github.com/sidebase/nuxt-auth/blob/a0704470583c5fea47c26c14b8673f8bb6a39a5f/src/runtime/composables/authjs/useAuth.ts#L120-L133
It works well when being called using HTTP, but fails when calling Nuxt endpoints from within a server. As you know,
$fetch
calls are translated to function calls in server code.Upon some investigation, I was able to find the exact culprit - it is the
readRawBody
method and itsBuffer.from
return statement: https://github.com/unjs/h3/blob/112fa338ef5bbde6207f3317d2ef51f0e52a59fa/src/utils/body.ts#L93This is what happens:
$fetch
serializesURLSearchParams
and is therefore capable to deserialize them later;readRawBody
receivesURLSearchParams
as-is;URLSearchParams
successfully evades all theif
checks and ends up in the last return statement.I fixed it locally and verified the patch, I will submit a PR shortly.
Additional context
No response
Logs
No response