SpaceX
SpaceX

Reputation: 575

Cookie not persistent in Cordova Android App

I'm using the jwttoken and passing it as HTTP only cookie to the React frontend. When I'm building this using Cordova, on reopening the app, cookie is persistent for iOS but not on Android. There are a lot of issues where people were facing this, but they were using a session cookie. I'm setting the expiresAt but still, when I close the app and reopen it, the cookie value is lost.

I tried removing HTTP only from my node backend, but still, I get an empty string on printing document.cookie in the Cordova app.

How does the cookie work with the Cordova?

Upvotes: 1

Views: 2211

Answers (1)

David
David

Reputation: 7507

Cookies are not a good way of storing data on mobile devices exactly because of the reasons you outlined in your question - data will get lost because of many reasons. On mobile devices there are multiple cookie stores (the webview has one, there is a native one, and I think even some HTTP modules have one) so they have to be in sync to work reliable. Android had its own CookieSyncManager as a utility for that (newer webviews are able to to it on their own). Also when your device is on low memory cookies are probably in front row to get cleared by the system.

So what should you do instead? Use native-storage ore some sql-lite storage to store data persistent on mobile devices. For the jwt-token in particular I would suggest using native-storage.

Upvotes: 2

Related Questions