Cookies are not automatically carried in redirection

See original GitHub issue

Describe the bug

I was on a sunny afternoon and I used axios to send a POST request to a website, and that website would redirect and use cookies to save the state in the middle… The tragedy happened here, and axios was automatically processing heavy After the orientation (302), the cookie was not saved .

Why not provide the option to open cookies in axios

I am using nodejs

Why are cookies prohibited in nodejs

To Reproduce

// Example code here

Expected behavior

A clear and concise description of what you expected to happen.

Environment

  • Axios Version [0.21.1]
  • Adapter []
  • Browser []
  • Browser Version []
  • Node.js Version [14]
  • OS: [windows]
  • Additional Library Versions []

Additional context/Screenshots

Add any other context about the problem here. If applicable, add screenshots to help explain.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

6reactions
chinesedfancommented, Oct 27, 2021

Mention 2 things may help.

  • Browsers handle redirections automatically. axios has no control for that.
  • Cookies belongs to domains. If the redirection destionation has different domains, your cookies may not be able to be shared.
2reactions
jgriffin1commented, Aug 9, 2021

I am having this same issue as well. I am working on a node project that will be able to test other websites for being up and down. At the moment, I am attempting to do a post request to an external site with some credentials in the params, and this is failing because cookies don’t seem to be readable after redirects. The same post request works perfectly in Postman and Insomnia. After performing the request in postman, I can actually go to the console in postman, and then copy and paste the cookie from the last redirect into my node js axios code and it works… but Axios can’t seem to make it that far through the redirects on it’s own.

edit: The Post request I’m making gets redirected twice, both redirections are Get requests. If I just skip that first post request, copy a cookie from Postman, and then make a Get request using Node.js and Axios, it can do the last redirect just fine. The issue is just for initial post request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sending browser cookies during a 302 redirect - Stack Overflow
Most browser are accepting cookies on 302 redirects. ... I just ran into this problem with both Firefox and Safari, but not Chrome....
Read more >
Cookies set with SameSite=strict are not sent in redirects
The situation is as follows: 1. User follows a link from domaina to domainb/first.html 2. domainb/first.html sets a samesite=strict cookie and redirects the ......
Read more >
Trouble setting a cookie and performing a redirect at same time
I'm trying to set up a route that checks for a query string and if it matches, set a cookie and then redirect...
Read more >
7 Keys to the Mystery of a Missing Cookie - Medium
7 Keys to the Mystery of a Missing Cookie · 1. SameSite attribute Defaults to Lax · 2. withCredentials is not Set to...
Read more >
696204 - Cookies are ignored on 302 redirects - Monorail
After testing this a little more, I was redirecting from `/oauth/google` to `/` which won't save the cookie without setting `path=/`. If I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found