Open Barbapapazes opened 3 days ago
This seems either like:
event.$fetch
- perhaps it should have a .create
function - cc: @pi0?Since the useRequestEvent
will return the correct fetch on client-side the useRequestFetch
must be the same as $fetch
(and this explains why the type is the same). So I think it's more the second point and an issue with the behaviour of $fetch.
https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts#L46
event.$fetch
in Nitro is not extendable. It is a wrapper for h3.fetchWithEvent
(the types are inaccurate and I guess we need to fix it most importantly -- PR welcome for upstream 👍🏼 ).
Adding all ofetch nested utils costs, and the exact purpose of event.$fetch
is to proxy incoming request not extending it. If you believe there are use cases for event.$fetch.create
please feel free to open a discussion.
Environment
Build Modules: -
Reproduction
api.ts
with the following content:__vite_ssr_import_1__.useRequestFetch(...).create is not a function
.Describe the bug
I'm trying to create an API version of the
$fetch
like in this video: https://www.youtube.com/watch?v=jXH8Tr-exhI&t=575sWhile this works very well on the client, it does not works on server side, when a request need to be performed from the server. Why I want this? Because I'm trying to link a Nuxt application with a Laravel API and I need to forward the authentication cookie to get the user data from
<laravel>/api/user
and this is only possible withuseRequestFetch
.But the typing system is not complainig about this:
Additional context
No response
Logs