Using readBody
with Nuxt internal routing fails to parse URLSearchParams
#887
Labels
bug
Something isn't working
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:h3/src/utils/body.ts
Line 93 in 112fa33
This 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
The text was updated successfully, but these errors were encountered: