N
Nuxt3mo ago
Edik

$fetch inside API

Hello, I try to do a nested fetch. First one is Clientside inside a page $fetch("/api/someApi"), second inside the server in this api inside
defineEventHandler(async (event) => { $fetch("/api/secondApi") })
defineEventHandler(async (event) => { $fetch("/api/secondApi") })
Why the second one doesnt work, and how to make a fetch from API to API?
2 Replies
Cue
Cue3mo ago
First, await the fetch.
Edik
EdikOP3mo ago
Ok, problem solved. I am using lucia auth, and it passed the cookies to the server which was validating it in server middleware. The second $fetch didnt pass thr cookies, so it didnt work. Instead you need to use event.$fetch Alexander Lichter released a video a few days ago about this topic: https://youtu.be/7vfwYaHtv3U
Alexander Lichter
YouTube
Passing Cookies with event.$fetch and useRequestFetch in Nuxt
Ever wondered why cookies are not passed correctly to subrequests - e.g. during SSR or when using Nitro/H3? Then this video is for you. Together we have a look how to pass all the important information, including event context and headers to further calls, eliminating different behavior on server and client. #nuxtjs #nuxt #vue #webdevelopment ...
Want results from more Discord servers?
Add your server