Cookies disappear on app restart

I’m currently using cookie-based authentication as described here: http://blog.ionic.io/angularjs-authentication/. It’s working well, until I restart the app. Every once in a while on Android and every time on iOS, after restarting the app, the authentication cookie is no longer sent with requests to my server. I’ve checked on the server and verified that post-restart, the cookies are empty.

Looking at the comments at the end of the article, it looks like I’m not the only one this is happening to. I really don’t want to do token-based authentication because we need to release this app ASAP and implementing a new authentication method would really set us back.

1 Like

Okay, thanks to this SO answer http://stackoverflow.com/a/8713316 I figured it out. This is happening because I’m not setting an expiry for the cookie. Browsers clear cookies without an expiry on close. I’m still not sure why I don’t see this every time on Android, but after setting an expiry, the cookie persists on iOS and Android.

1 Like

I’m facing a similar issue with my ionic ios application with a PHP backend API when PHPSESSID stored is in the Cookie of HTTP Request Header (when I add withCredentials = true in my RequestOptions).

I have tried IOS native code as the answer to the solution but it did not work
https://stackoverflow.com/questions/41009777/ionic-ios-session-issue

Please help me if we could do something in js.
Thanks In Advance

please how did you set the expiry to the cookie help me please