N
Nuxt3mo ago
LordGhandi

Nuxt auth utils cookie compatible

I have a 3rd party api which authenticates with cookies. Does nuxt automatically provide a fetch function which includes the cookies from that domain?
4 Replies
kapa.ai
kapa.ai3mo ago
Hi @LordGhandi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Short answer: not automatically for third-party domains. - On the server (SSR), Nuxt’s $fetch does not forward browser cookies by default. It only auto-forwards headers/cookies when you use useFetch (or useRequestFetch) with relative, internal URLs. For external/third‑party APIs, you must manually pass the needed headers (e.g., cookie) yourself (or use useRequestFetch to proxy them) ($fetch, useRequestFetch, Getting Started: Passing Headers and Cookies). - On the client (browser), the browser will send cookies for that third‑party domain according to normal CORS and cookie policies, but that’s outside Nuxt’s control. Nuxt doesn’t “include” third‑party cookies in server requests automatically (Getting Started: Passing Headers and Cookies). If you need SSR calls to a third‑party API to include cookies, forward them explicitly, for example: - Use useRequestHeaders(['cookie']) and pass them to $fetch, or - Use useRequestFetch to proxy headers/cookies in SSR (useRequestFetch, Getting Started: Pass Client Headers to the API). Note: Nuxt Auth Utils stores session in sealed cookies for your Nuxt app; it doesn’t automatically bridge those cookies to third‑party domains (Sessions and Authentication). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@358749735323959308> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
LordGhandi
LordGhandiOP3mo ago
@kapa.ai I'm not sure I understand, if I forward the cookie headers to the client, e.g. forwarding the Set-Cookie the domain of the cookie will change to the nuxt servers domain. How would I be able to make requests to the 3rd party api if the domain is not the same? @kapa.ai I'm not sure I understand, if I forward the cookie headers to the client, e.g. forwarding the Set-Cookie the domain of the cookie will change to the nuxt servers domain. How would I be able to make requests to the 3rd party api if the domain is not the same? @kapa.ai
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: Sorry @LordGhandi, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?

Did you find this page helpful?