npx cap doctor output:
@capacitor/ios not installed
@capacitor/cli 1.5.2
@capacitor/core 1.5.2
@capacitor/android 2.1.0
Android native Cookies management persists cookies only after a given amout of time.
This causes problems when an auth session cookie or remember me cookie are used and the application is destroyed shortly after the login (or any other action creating a cookie) is performed.
When re-started, we won't have that cookie available.
A similar problem is present on iOS too, but haven't yet tried it out (link at the end of the issue).
Cookies shall be forcefully persisted when onPause or onStop is called, to be sure to avoid data loss in case the app is later destroyed (by the user or by the system).
yarn --version output: 1.22
node --version output: 13.x
This article explain the problem pretty well.
https://github.com/ionic-team/capacitor/issues/2347 seems to report the same problem
https://github.com/ionic-team/capacitor/issues/2831 seems to be related, but not sure
Simply adding the following to my MainActivity.java fixed the problem.
Could probably be onStop instead, but I'm not sure if Android persist cookies even when the app is paused
import android.webkit.CookieManager;
public class MainActivity extends BridgeActivity {
// ...
@Override
public void onPause() {
super.onPause();
CookieManager.getInstance().flush();
}
// ...
}
Most helpful comment
Simply adding the following to my
MainActivity.javafixed the problem.Could probably be
onStopinstead, but I'm not sure if Android persist cookies even when the app is paused