Cookies are lost on iOS after application closing
Cookies seems to be lost after closing an application. Is it expected behaviour?
Environment:
- OS: iOS
- react-native version: 0.57.7
- react-native-webview version: 5.2.4
Having the same problem on Android.
Environment:
- OS: Android
- react-native version: 0.59.5
- react-native-webview version: 5.7.0
having the same problem on both android and ios
react native - .57.8 react-native-webview version - 5.3.0
Same :/
I have the same Issue, I guess. The Cookies are not lost directly after closing the App (swiping the App up in iOS) or after a restart of the Phone. But after some Time. The Cookie Lifetime is set to 10 Yrs, but the User gets logged out after Days/Weeks.
I wrote about the Problem here: https://stackoverflow.com/questions/56440239/react-native-webview-user-gets-logged-out-despite-10-year-login-cookie
Seems like cookie used to be persisted. Maybe this bug appeared just recently? https://github.com/react-native-community/react-native-webview/issues/207#issuecomment-498321766
Any updates regarding this, it appears to happen at random but sometimes even after just a few hours.
Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically
Any progress on this? There is no cookie issue in android. But in iOS, on closing the app, the cookie is getting automatically cleared it seems and the user will be landed on login screen on reopening the app, which is not acceptable.
You need to ensure that the cookies have an expiry date set on the server-side. Cookies without an expiry date are considered 'session only' and will get cleared when you restart the app.
That worked for me
We had a bug that sometime clearing PHPSESSID (which is a session only cookie) cleared the auth as well, resolving it fixed the issue indeed
We also experience this problem
i have resolved issue and tested with php. you can check my solution here: https://stackoverflow.com/a/62071590/8079868
This may sound silly but I was facing same issue just today. The session was persisting on Android but not on IOS so I easily believed it was an issue with IOS.
but after hours of debugging, I realized it was my own mistake. I forgot to declare session_start() in my php file. But I'm still confused how android managed to work fine without that declaration.
Is there any solution for case when I don't have the ability to fix that on the server?
Firstly, try to explain what exactly is the behavior you want so we can know if using cookies is the best option in the first place. Cookies might function perfectly in some scenarios for a website but might not be the case for an app.
I am making a mobile application for a website, that does not have one and since I cannot reverse engineer websocket comminucation to use the API, all I can do is to just use WebView and rely on it and the website to handle login cookies. The thing is that currently, the WebView will delete all of the website's cookies so I have to login each time after restarting the application.
The issue is still there on android it keeps logging me out fir certain amount of time on first install whenever I kill the app and after certain time it starts working properly
Packages: "expo": "51.0.8", "react": "18.2.0", "react-native": "0.74.1", "react-native-gesture-handler": "~2.16.1", "react-native-webview": "^13.8.6"
I believe you already generate authentication token upon login. This authentication token is stored in the app's async storage. A copy of the token is also stored on the server along with the id of the account associated with it.
Whenever the app is opened again after being closed, the token is fetched from the async storage and a request is sent to the server with it. On the server, you'll query the database with the token to know if it exists and you'll fetch the user id associated with it. You'll then create a new session. The php file doing the checks and creating the session must have session_start() at the top. You'll initiate the session by setting $_SESSION['id'] to the user's id (or any other identifier you use)
With this, subsequent calls made from the app to the server will keep that same $_SESSION until the app is closed.
So in my case, the only mistake I made was omitting session_start() at the top of my php file. This made me logged in for first few API calls from the app then I noticed I wasn't logged in again on subsequent calls.
Why is this issue closed? I have the same problem. Cookies are gone from webview after app has been in background for a while!
Same here.
- Cookies are gone from Webview not only when you've been on the background for a while.
- Cookies are gone if you shut down an app immediately after setting a cookie.
Point two can be resolved by just waiting for 20 seconds or more, I guess cookie is being preserved with some delay, like described here