Hi there, is there a way of using cookies ( react-native-cookies ) etc… without eject ? because our code is in jsbundle format and is only a part of an existing native project, moreover, we do not have native code by side. thanks !
Obviously, the existing native part can offer a cookie bridge to manage that kind of native functionality, but due to separate working environment, plus we do not want to eject, it is hard to find a way of doing that, expo seems not providing that component for a reason ?
: we are using cookies only because of sharing login status while sending requests
I don’t think we offer access to shared cookies right now without ejecting. You might be able to use the WebBrowser module (which uses the device browser, with shared cookies) to capture a login access token and send that back to your app’s JS. Would that work for you?
Thanks for the reply, I’ll try it out, moreover, I was trying to manually write Cookie into the header of fetch request (only for local dev purpose), it works with iOS ( with a expo user agent ), but seems to be overwritten by the okhttp user agent in Android (5.0+ testing device), is it suppose to be like that ?
Thank you guys @ben@jesse for delivering the great product for us!
I had the same problem that I don’t want to eject but I need to get JWT from Cookies while I am making OAuth2 through the WebView component. And this gist is what I came up with. I am not sure if it is going to work in your use case because it is kind of tricky solution I believe but you might want to play around with it
This might be a bit of a stretch but the way we ended up doing it was by sending out the cookie to store as field in the response for the authentication request. Then we used AsyncStorage to store the cookie and manually set it in the header for every subsequent request. (Basically becomes token based authentication) Ended up working out for us for the time being until there’s persistent cookie support.
Note: This might not work if your cookies get updated in other requests
Hey @zuhayeer how did you include it in the header, trying to figure out what they code should looklike, since I came under the same conclusion of just using AsyncStorage to store the cookie token then pass it back in the header as a “cookie”
I had a function to get the headers before making the fetch request where I’d retrieve the key from local storage. If the key exists, I add it to the headers cookie field
import RCTNetworking from 'react-native/Libraries/Network/RCTNetworking';
But it isn’t working properly, at least in iOS. My best guess by now is that RCTNetworking.clearCookies is trying to remove cookies using NSHTTPCookieStorage instead of WKHTTPCookieStore that it seems to be used by WKWebView.