Ajax/Axios cookies not being set, but still being included in following requests

For some reason cookies set by server are not being saved, can’t access them from within my js code, in devtools in Application tab in cookies section it’s all empty, but somehow when I make a request to the server after the initial one, those cookies that apparently didn’t save are being included in the header.

I have set withCredentials to true in axios config, as well as CORS_ALLOW_CREDENTIALS to true on my backend.

Here are the headers from the request that should save cookies:

Response Header:

access-control-allow-credentials: true
access-control-allow-origin: <frontend url>
content-length: 22
content-type: text/html; charset=utf-8
date: Mon, 01 Feb 2021 12:04:09 GMT
server: nginx/1.19.2
set-cookie: csrftoken=<token>; expires=Mon, 31 Jan 2022 12:04:09 GMT; Max-Age=31449600; Path=/; SameSite=Lax
set-cookie: sessionid=<sessionid>; expires=Mon, 01 Feb 2021 13:04:09 GMT; HttpOnly; Max-Age=3600; Path=/
strict-transport-security: max-age=31536000
vary: Cookie, Origin
x-frame-options: SAMEORIGIN

Request Headers:

:authority: <backend url>
:method: POST
:path: /login/
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
content-length: 66
content-type: application/json;charset=UTF-8
dnt: 1
origin: <frontend url>
pragma: no-cache
referer: <current frontend url query>
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36

As you can see in the response I’m getting two cookies to be set, sessionid and csrftoken, those are not being saved.

What’s weird those cookies are present in the following request:

Request Headers:

:authority: <backend url>
:method: GET
:path: /numbers/
:scheme: https
accept: application/json, text/plain, */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
cookie: csrftoken=<token>; sessionid=<sessionid>
dnt: 1
origin: <frontend url>
pragma: no-cache
referer: <current frontend url query>
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36

How is it possible for the cookies to not be set but still included in the request? And what can cause this behavior? I really need them to be saved.

My backend and frontend are located at different urls, my backend is running on Django with a rest-framework.

127 thoughts on “Ajax/Axios cookies not being set, but still being included in following requests”

  1. 486866 650262Oh my goodness! an wonderful write-up dude. Thanks a ton Nonetheless I is going to be experiencing issue with ur rss . Do not know why Not able to join it. Can there be every person acquiring identical rss problem? Anybody who knows kindly respond. Thnkx 3131

    Reply
  2. That is a great tip particularly to those fresh to the
    blogosphere. Brief but very precise info… Appreciate your
    sharing this one. A must read post!

    Reply
  3. Hi I am so happy I found your website, I really found you by mistake, while I was looking on Aol for something else, Anyways I am here now and
    would just like to say kudos for a tremendous post
    and a all round enjoyable blog (I also love the theme/design), I don’t
    have time to browse it all at the moment but I have saved
    it and also included your RSS feeds, so when I have time I will be
    back to read a great deal more, Please do keep up the great job.

    Reply
  4. It is perfect time to make a few plans for the longer term
    and it is time to be happy. I’ve learn this submit and if I
    may I desire to counsel you few fascinating things or
    tips. Perhaps you can write next articles referring to this article.
    I desire to learn more issues approximately it!

    Reply
  5. Just wish to say your article is as astounding. The clearness
    in your post is simply spectacular and i
    could assume you are an expert on this subject.
    Well with your permission allow me to grab your feed to keep up to
    date with forthcoming post. Thanks a million and please continue the gratifying work.

    Reply
  6. Greetings I am so thrilled I found your weblog, I really found you by mistake,
    while I was researching on Google for something
    else, Anyways I am here now and would just like to say thanks a lot
    for a tremendous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to browse it all at
    the moment but I have saved it and also added in your
    RSS feeds, so when I have time I will be back to read a great deal
    more, Please do keep up the excellent work.

    Reply
  7. Your style is so unique compared to other folks I have read stuff
    from. Thank you for posting when you’ve got the
    opportunity, Guess I will just bookmark this page.

    Reply
  8. My brother recommended I may like this web site. He used to be totally right.
    This put up truly made my day. You can not imagine just how much
    time I had spent for this info! Thank you!

    Reply
  9. Thanks for your marvelous posting! I really enjoyed reading
    it, you happen to be a great author. I will always bookmark
    your blog and may come back down the road. I want to encourage continue your great work, have a nice morning!

    Reply
  10. I have been browsing online more than three hours today, yet I never found any interesting article like yours.
    It is pretty worth enough for me. Personally, if all site owners and bloggers made good content as you
    did, the internet will be a lot more useful than ever before.

    Reply
  11. Oh my goodness! Impressive article dude! Thank you so much, However I am going through troubles
    with your RSS. I don’t understand why I cannot join it.
    Is there anybody else having the same RSS
    problems? Anyone that knows the solution will you kindly respond?
    Thanks!!

    Reply
  12. I know this if off topic but I’m looking into
    starting my own weblog and was curious what all is needed to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet savvy so I’m not 100% positive.
    Any tips or advice would be greatly appreciated.
    Cheers

    Reply
  13. Hmm is anyone else having problems with the pictures
    on this blog loading? I’m trying to find out if its a problem
    on my end or if it’s the blog. Any suggestions would be
    greatly appreciated.

    Reply
  14. Hi there, I discovered your site by way of Google while looking for a related matter,
    your site got here up, it appears great. I’ve bookmarked it in my google bookmarks.

    Hi there, simply become aware of your blog through Google, and located that it is really informative.
    I am going to be careful for brussels. I’ll be grateful for those who continue this in future.
    Numerous people will likely be benefited from your writing.

    Cheers!

    Reply
  15. I am really impressed with your writing skills as well as
    with the layout on your weblog. Is this a paid theme or did
    you customize it yourself? Either way keep up the excellent quality writing,
    it’s rare to see a great blog like this one these days.

    Reply
  16. Hiya! I know this is kinda off topic however I’d
    figured I’d ask. Would you be interested
    in trading links or maybe guest authoring a blog
    article or vice-versa? My site discusses a lot of the same subjects
    as yours and I believe we could greatly benefit from each other.
    If you happen to be interested feel free to send me an email.
    I look forward to hearing from you! Excellent blog by the way!

    Reply
  17. Write more, thats all I have to say. Literally,
    it seems as though you relied on the video to make your point.

    You clearly know what youre talking about, why throw away your intelligence on just posting videos to your weblog
    when you could be giving us something enlightening to read?

    Reply
  18. Woah! I’m really loving the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s very difficult
    to get that “perfect balance” between superb usability and visual appearance.

    I must say that you’ve done a awesome job with this. Additionally,
    the blog loads extremely quick for me on Firefox. Outstanding Blog!

    Reply
  19. After exploring a number of the blog articles
    on your blog, I really appreciate your way of blogging.

    I book-marked it to my bookmark website list and will be checking back
    in the near future. Please visit my website as well and
    let me know what you think.

    Reply
  20. An outstanding share! I’ve just forwarded this onto a co-worker who has been doing
    a little research on this. And he actually bought me lunch simply because I stumbled upon it for him…

    lol. So let me reword this…. Thanks for the meal!!
    But yeah, thanx for spending time to talk about this subject here
    on your site.

    Reply
  21. I think that everything said was very reasonable.
    However, consider this, what if you composed a catchier post
    title? I am not saying your content is not good., but suppose you added something that grabbed people’s attention? I
    mean Ajax/Axios cookies not being set, but still being included in following requests – JavaScript Help is a little
    boring. You might glance at Yahoo’s front page and
    note how they create news headlines to grab people
    to open the links. You might try adding a video or a related picture or
    two to grab readers excited about what you’ve got
    to say. In my opinion, it might bring your posts a little bit more interesting.

    Reply
  22. Thanks for every other informative website. Where else could I get that type of information written in such an ideal
    way? I have a project that I’m simply now operating on, and
    I’ve been at the look out for such information.

    Reply
  23. Pretty great post. I simply stumbled upon your blog and wanted to say that I’ve truly loved
    surfing around your blog posts. After all I’ll be subscribing on your feed and I
    hope you write once more soon!

    Reply
  24. I really like your blog.. very nice colors & theme.

    Did you make this website yourself or did you hire
    someone to do it for you? Plz answer back as I’m looking to design my
    own blog and would like to find out where u got this from.
    many thanks

    Reply
  25. First off I want to say awesome blog! I had a quick question in which I’d like to ask if you do not mind.
    I was interested to know how you center yourself
    and clear your mind before writing. I’ve had trouble clearing my thoughts in getting my ideas out
    there. I truly do enjoy writing however it
    just seems like the first 10 to 15 minutes are lost simply just trying to figure out
    how to begin. Any ideas or hints? Cheers!

    Reply
  26. I simply could not go away your site before suggesting that I really enjoyed the usual info an individual supply in your guests?
    Is gonna be again ceaselessly to investigate cross-check new posts

    Reply
  27. Hi there! I realize this is sort of off-topic however
    I needed to ask. Does managing a well-established website such as
    yours require a massive amount work? I’m brand new to operating a blog but
    I do write in my diary everyday. I’d like to start a blog so I will be able to share my experience and feelings online.
    Please let me know if you have any ideas or tips for new aspiring blog owners.
    Appreciate it!

    Reply
  28. hey there and thank you for your info –
    I have definitely picked up anything new from right here.
    I did however expertise several technical points using this website, since I experienced to reload the
    web site many times previous to I could get it
    to load properly. I had been wondering if your web host is OK?
    Not that I’m complaining, but sluggish loading instances times
    will very frequently affect your placement in google and could damage your quality score
    if advertising and marketing with Adwords. Anyway I am adding this RSS to my e-mail and can look out for much more of your respective interesting content.

    Ensure that you update this again soon.

    Reply
  29. First off I want to say superb blog! I had a quick question which
    I’d like to ask if you do not mind. I was interested to
    know how you center yourself and clear your head prior to writing.
    I’ve had difficulty clearing my thoughts in getting my ideas out.

    I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally wasted simply just trying to figure
    out how to begin. Any suggestions or tips? Thanks!

    Reply
  30. Hi I am so delighted I found your blog page, I really found you by accident, while I was searching on Digg
    for something else, Anyhow I am here now and would just like to say
    thanks a lot for a marvelous post and a all round interesting blog (I also
    love the theme/design), I don’t have time to browse it
    all at the moment but I have saved it and also added in your
    RSS feeds, so when I have time I will be back to read a lot more, Please do
    keep up the excellent job.

    Reply
  31. Hello, i think that i saw you visited my weblog thus i
    came to go back the choose?.I’m trying to find issues to improve my website!I guess its ok to make use of a few of your concepts!!

    Reply
  32. I like the helpful info you provide in your articles. I will bookmark your blog and check again here frequently.
    I am quite certain I’ll learn many new stuff right here!
    Best of luck for the next!

    Reply
  33. Hello there! This is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche.
    Your blog provided us useful information to work on. You have done a
    extraordinary job!

    Reply
  34. I wanted to thank you for this good read!! I certainly enjoyed every bit
    of it. I have got you saved as a favorite to check out new stuff you post…

    Reply
  35. Having read this I believed it was really enlightening. I appreciate you taking the time and effort to put this article together.
    I once again find myself spending way too much time both reading and leaving comments.
    But so what, it was still worthwhile!

    Reply
  36. Unquestionably believe that which you said. Your favourite reason seemed to
    be on the internet the easiest thing to understand of.
    I say to you, I certainly get annoyed whilst people think about
    concerns that they just do not recognize about. You managed to hit the nail
    upon the top and also defined out the entire thing with no need side-effects ,
    other people could take a signal. Will probably be again to get more.
    Thanks

    Reply
  37. Undeniably believe that which you said. Your favorite reason appeared to be on the web the easiest thing to be aware of.
    I say to you, I certainly get irked while people think about worries that they just do not know about.

    You managed to hit the nail upon the top as well as defined
    out the whole thing without having side effect , people can take a signal.
    Will probably be back to get more. Thanks

    Reply
  38. Undeniably believe that which you said. Your favorite
    justification appeared to be on the net the simplest thing to be aware of.

    I say to you, I definitely get irked while people think about
    worries that they just don’t know about. You managed to hit
    the nail upon the top as well as defined out the whole thing without having side-effects ,
    people could take a signal. Will probably be back to get more.
    Thanks

    Reply
  39. Greetings, I believe your blog might be having browser compatibility problems.
    When I take a look at your website in Safari, it looks fine however when opening in I.E.,
    it has some overlapping issues. I simply wanted to give you a quick
    heads up! Other than that, wonderful website!

    Reply
  40. Hi there! Someone in my Myspace group shared this site
    with us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers!

    Terrific blog and great design.

    Reply
  41. Hey! I understand this is somewhat off-topic however I needed to ask.

    Does building a well-established website like yours take a large amount
    of work? I am brand new to writing a blog but I do write in my
    journal on a daily basis. I’d like to start a blog so I can share my personal experience and
    thoughts online. Please let me know if you have any suggestions
    or tips for new aspiring blog owners. Thankyou!

    Reply