Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credentials support? #49

Open
nezed opened this issue Oct 2, 2015 · 9 comments
Open

Credentials support? #49

nezed opened this issue Oct 2, 2015 · 9 comments

Comments

@nezed
Copy link

nezed commented Oct 2, 2015

On client-side we can deal with cookies specifying credentials option.
https://fetch.spec.whatwg.org/#concept-request-credentials-mode
But, have any idea about cookies on server-side (node-fetch)?

@XeeD
Copy link

XeeD commented Oct 2, 2015

You should add them manually as headers. You can in fact use the same code for server and for client, because on client the Cookie headers are ignored and credentials: 'include' works instead.

fetch('/', {
  credentials: 'include',
  headers: {'Cookie': 'foo=bar;bar=foo'}
})

@nezed
Copy link
Author

nezed commented Oct 19, 2015

@XeeD not great, but works.
Thanks!

@coverslide
Copy link

Hi, I'm having an issue where cookies that are set in between redirects are not persisted. With the request module, this is handled much more cleanly, but I would love to use the fetch spec if I can. In the browser it works perfectly fine, but since node-fetch requires cookies to be handled manually it doesn't perform the same way as on the browser, and breaks in my case.

@bitinn
Copy link
Collaborator

bitinn commented Nov 3, 2015

@coverslide this question finally comes, the short answer is: node-fetch doesn't have a concept of cookies at the moment. If you are facing a POST then redirect then GET request, it breaks.

Any library (request for example) implementing such support use custom cookie store, which is not trivial in server-side context.

@bitinn
Copy link
Collaborator

bitinn commented Nov 17, 2015

closing this issue as the main problem has a workaround.

(added coverslide's suggestion to #8, it's something we would like to provide a workaround, possibly by implementing redirect header extraction)

@lillem4n
Copy link

Why close this when it still is an issue? The "real" solution must be to add the same support server side as client side, no?

@itskibo
Copy link

itskibo commented Oct 2, 2019

I agree with @lillem4n, this issue is far from being solved.

I cannot set cookies through HTTP, and then later on use them in fetch requests that require these cookies.
This is regardless of whether the credentials header is set or not.

Edit: manually getting and setting the cookies as headers sort of works, as mentioned in #49 (comment), but this works around the purpose of credentials, as you have to manually keep track of these cookies.

This limit is mentioned in LIMITS.md, but there is no mention of solving this in the v3 roadmap, so this does raise some concern for me.

@itskibo itskibo mentioned this issue Oct 2, 2019
35 tasks
@xxczaki xxczaki reopened this Oct 2, 2019
@xxczaki
Copy link
Member

xxczaki commented Oct 2, 2019

@lillem4n @itskibo Reopening this, as it is indeed still an issue.

@AlenToma
Copy link

AlenToma commented Jan 1, 2022

Same problem here, works greet with regular fetch but not with node-fetch and not with axios either sadly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants