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

Set-Cookie response header is not working on react-native 0.44.0 #14154

Closed
nsisodiya opened this issue May 24, 2017 · 15 comments
Closed

Set-Cookie response header is not working on react-native 0.44.0 #14154

nsisodiya opened this issue May 24, 2017 · 15 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@nsisodiya
Copy link

I have created a Github repo for showcasing the bug.

Problem

When App make a XHR request for login. Login server sends cookie. App send XHR to get data and server read auth cookie on XHR. This is working fine with Android. However same code is not working with iPhone. At server side I am getting following logs. JWT token is undefined

How to reproduce this bug

cd react-native-cookie-bug
yarn install
react-native run-ios

On iPhone Simulator, this will print like this

image

On Android , this print like this
image

Online Demo

Created https://snack.expo.io/BJAHjhMb- online demo, but here things are working fine because they are using Expo 16 which use react 0.43.4 where this bug do not present.

@nsisodiya nsisodiya changed the title Set-Cookie response header is not working on 0.44.0 version for iPhone Set-Cookie response header is not working on react-native 0.44.0 May 24, 2017
@hramos
Copy link
Contributor

hramos commented May 24, 2017

Isn't this a duplicate of #14063?

@nsisodiya
Copy link
Author

nsisodiya commented May 24, 2017 via email

@DanielZlotin
Copy link
Contributor

Yes same issue, see #14064 for the fix

@hramos hramos closed this as completed May 25, 2017
@deepaksisodiya
Copy link

@nsisodiya You should try this
fetch(url, {
credentials: 'include',
...otherOptions,
});

@nsisodiya
Copy link
Author

nsisodiya commented Jun 12, 2017 via email

@Piyush905
Copy link

@nsisodiya I am facing the same problem which you mentioned "On ios, if you close the app, cookie will be deleted". I stored the Cookie in AsyncStorage but I am not able to figure it out -"how to load back the cookie into our app". I want to use the stored cookies for Fetch request. Any idea?

@Palisand
Copy link

Palisand commented Oct 5, 2017

@Piyush905 You can store the cookie in AsyncStorage, although you should not do so if the cookie holds sensitive information (use this instead and consider the keystore branch if you're targeting android 18+), and use react-native-cookie to set it again.

Note, I am experiencing cookie deletion on Android as well.

@Piyush905
Copy link

@Palisand Thanks. Yes, I am doing the same way. But, is there any other way where we can directly push cookie into the Fetch without using react-native-cookie. Also, I am facing challenge to get cookie from Webview (without react-native-cookie) once authentication is successful.

@Palisand
Copy link

Palisand commented Oct 7, 2017

The only other way, as far as I know, is to make the API call that sets the cookie header every time you start the app. If you're dealing with a user session, you would securely store credentials on the device and re-authenticate on app startup. However, this can render cookie expiration moot.

@almirfilho
Copy link

Using RN 0.49 and neither credentials: 'include' nor withCredentials: true are working.

@aqnaruto
Copy link

aqnaruto commented Oct 31, 2017

@Palisand how to store cookies in asyncstorage or delete cookie?
when i using cookie, credentials: 'include' ,session expiration time is out,so,i relogin, the server is updating session, but, my cookie is still not updated in some device such as android 5.5 ,ios 10.1

@Palisand
Copy link

Palisand commented Oct 31, 2017

@aqnaruto Can't you just use react-native-cookie or react-native-cookies to access the cookie you want to store in device storage?

import {AsyncStorage} from "react-native";

const cookie = getCookieWithOneOfTheLibrariesStatedAbove();
AsyncStorage.setItem(cookie.name, cookie.value);

For deleting specific cookies, you'd want to use react-native-cookies's (that's with an "s"!) clearByName, and for removing them from storage, just call AsyncStorage.removeItem.

As I mentioned in a previous comment, do not use AsyncStorage if your cookie is holding sensitive data, like an authentication token! It is an unencrypted store, so if a user's device is rooted or jailbroken, their information is at risk of exposure.

If you are storing sensitive data, please consider using iOS's keychain and/or Android's keystore. Please read this short blog post before choosing a secure storage library.

@aqnaruto
Copy link

aqnaruto commented Nov 1, 2017

@Palisand thankyou ,but, i have tried react-native-cookies before,but it not works well on reactnative0.44&0.46 ,
okay,mabe i should try it more

@Palisand
Copy link

Palisand commented Nov 1, 2017

@aqnaruto Please let me know if it does work out. Just out of curiosity, are you using cookies for session authentication? If that's the only reason you're using them, then you should consider switching to token-based auth. Sorry I could not be of more help.

@aqnaruto
Copy link

aqnaruto commented Nov 1, 2017

@Palisand thankyou , yeah i am using cookies for session authentication,i using session to storage user's base info in various page, i don't want to change backend code to switch token-based now.
when i using react-native-cookies ,it's caused my app a lot error occured , such as react-navigation's view can't find、android compile error....

maybe i should try it more...

@facebook facebook locked as resolved and limited conversation to collaborators May 29, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

9 participants