-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Automatic cookies #1274
Comments
They're automatically managed by the Objective-C network stack, which is used internally by fetch. We haven't exposed any explicit support for them though. This would need to be implemented as a native "RCTCookieJar" module. |
Thanks for the clarification, I'll keep it in mind. |
How to get the cookie in client? |
@iostalk I've created a basic cookie manager that allows you to get/set cookies from react native: https://github.com/joeferraro/react-native-cookies |
Awesome @joeferraro |
thank you @joeferraro |
@joeferraro I'm trying to use your cookie manager, everything is in place, I require it successfully, but when I try to call any method on the object CookieManager it throws this error: This is my code: |
@xavibonell did you include the native RNCookieManagerIOS.h/m files in your Xcode project? It's not sufficient just to require the js. |
@joeferraro this is likely to be a common source of confusion. It might be a good idea to include an invariant inside your index.js to the effect of:
|
@joeferraro I am faced with the same issue as @xavibonell |
For anyone curious about React Native cookie handling I made an example project that shows how to use cookie authentication. It makes use of the library from @joeferraro https://github.com/ryanmcdermott/react-native-login |
Thanks for sharing, @ryanmcdermott! Added it to the newsletter for this week |
@brentvatne Thank you I appreciate it! |
hi there, I just wanted to check if my best case is to use https://github.com/joeferraro/react-native-cookies or if there is another way to simply clear / override the Cookie header in Fetch. I'm using Fetch like this: fetch(ENDPOINT, { Which only works after the first visit, the first one seems to send double Cookie's because fetch has grabbed one from an initial login request and saved it. When it does the request it sends two sets of cookies which confuses the endpoint server and doesn't accept the connection. But after that because the automatic cookie is no longer there it then works. So basically I think if I can just either clear the automatic cookie before I run this call, or make sure in my call where I set cookie above that it is the ONLY one being set. Do you think installing https://github.com/joeferraro/react-native-cookies and running clear cookies before this call will be my best bet? Hope this makes sense. Vince |
I am wondering the same thing as @vince-rowe. I don't use cookies, but fetch is using them in the background and I would just like to delete or override them in fetch without installing a third party library. |
I also want to find an easy solution to disable cookies at all. |
@ms88privat @kristojorg by default, If you're still having issues, you may want to try
|
@hbd I don't need it anymore, but I beleave, it wasn't the case. I also tried the credential property and so on. Like they said, it is managed by objective-c and not the fetch API |
two sets of cookie troubles me... wish a solution. |
@ms88privat Have you found the solution to disable cookies. I have the same problem."credentials: 'omit'" dosen't work |
Same issue. An external API in which I have no control is throwing 403s when a cookie is detected. Seems like there is a double-cookie issue as overriding the API's PHPSESSID did not help. The same override worked when using Postman. |
I am also trying to handle cookies entirely within Javascript and seeing the same Android issue where the cookies are set regardless of |
Also have this problem, |
@vince-rowe Here's how I removed cookies from my requests: After authenticating my user, I took the cookie off of the response header. Then I save the cookie to AsyncStorage. Next, I use react-native-cookies (https://www.npmjs.com/package/react-native-cookies) to clear all of the cookies saved on the native side. Then, on any request that needs the cookie, I take it from AsyncStorage and add it to the header to my request using axios (https://www.npmjs.com/package/axios).
|
Please feel free to correct me.
I've tried to use the
fetch
api to login against a service which sets a cookie in case of success.The session cookie gets correctly set and subsequent requests to the same service pass authentication without me configuring anything at the code level, which makes me assume that cookies are automatically managed by the JavascriptCore runtime.
I can't find a way to manipulate them though, is that by design?
As a side note, does this mean that I'm just better off using a different authentication flow?
Thanks for your work on this!
The text was updated successfully, but these errors were encountered: