useFetch & URLSearchParams nuxt3 global middlewere
Guys i'm trying out
useFetch
inside my global middlewere (ts file) I basically want to sent http request from the server side and use URLSearchParams
as my API requires it
with this code I'm getting following error:
Error: Unknown object type "urlsearchparams" at Object._object (index.mjs?v=b79dfc53:57:17) at Object.dispatch (index.mjs?v=b79dfc53:34:30) at Object._array (index.mjs?v=b79dfc53:88:16) at Object._object (index.mjs?v=b79dfc53:53:30) at Object.dispatch (index.mjs?v=b79dfc53:34:30) at objectHash (index.mjs?v=b79dfc53:13:10) at hash (index.mjs?v=b79dfc53:481:56) at useFetch (fetch.mjs?v=b79dfc53:6:28) at default (auth.server.global.ts:23:7) at fn (nuxt.mjs?v=b79dfc53:141:27)URLSearchParams should be available in Node so what's going on?
2 Replies
You don't need to wrap your params in
URLSearchParams
. using a JS object is fineSee https://github.com/unjs/ofetch#%EF%B8%8F-adding-query-search-params (useFetch uses ofetch under the hood)
GitHub
GitHub - unjs/ofetch: 😱 A better fetch API. Works on node, browser ...
😱 A better fetch API. Works on node, browser and workers. - GitHub - unjs/ofetch: 😱 A better fetch API. Works on node, browser and workers.