#Axios instance not sending cookies, only HttpOnly Cookie

4 messages · Page 1 of 1 (latest)

cerulean bloom
#

I have this code in axios.ts, i call the function aciosInstance everytime i'm doing a request

  baseURL: "http://localhost:8080/",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  timeout: 60000,
  withCredentials: true,
});```

I have a cookie called region that is manually set on my FE when the page loads and if i go to the application tab i can see my cookie set correctly but looking at the network request i don't see my cookie being send.

I have this piece of code before to set the cookie if it's not already for some reason 

```if (!Cookies.get("region")) {
  Cookies.set("region", "en-au", { path: "/", domain: "localhost" });
}```
I'm using js-cookie library fo ts files to manage cookies, but doing a console.log i'm getting undefined for Cookies.get("region")

So apparently my cookie is not been set correctly, even though i can see it in my application tab.

If i change my code like this the cookie is send and everything works as expected.

```const axiosInstance = axios.create({
  baseURL: "http://localhost:8080/",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
     Cookie: `region=en-au}`
  },
  timeout: 60000,
  withCredentials: true,
});```

I'm using SSR, so why i can't access to my region cookie in the .ts file?
meager sailBOT
#

Hi @cerulean bloom. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

I'm sorry, but the information provided in the knowledge sources does not contain specific details about Axios or the js-cookie library. The knowledge sources are primarily focused on the Astro framework and its cookie handling capabilities.

However, it's worth noting that in Astro, cookies can be accessed and manipulated using Astro.cookies as mentioned in the Astro documentation (https://docs.astro.build/en/reference/api-reference/#contextcookies). If you're using Astro, you might want to consider using its built-in cookie handling capabilities.

For issues related to Axios and js-cookie, I would recommend referring to their respective documentation or seeking help from their communities.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@cerulean bloom kapa.ai is still learning and improving, please let us know how it did by reacting below