I have a cordova application where i have a login page and an inner page for logged in users. Whenever the user session is gone it asks for a login information. How do i prevent ths cordova app to drop sessions uppon restart or restore the cookies and session information when restarting the mobile app? So the login screen doesn't show up everytime?
Asked
Active
Viewed 799 times
-1
-
Care to explain why the down vote? – Playdome.io Apr 29 '17 at 03:09
-
Possible duplicate of [localStorage vs sessionStorage vs cookies](http://stackoverflow.com/questions/29960037/localstorage-vs-sessionstorage-vs-cookies) – Playdome.io Apr 29 '17 at 03:12
-
Why down vote?? – Playdome.io May 29 '17 at 11:31
2 Answers
3
What you should be using is localStorage
to set any non-sensitive information you would need to check if the user has created an account. localStorage stays even after the user closes the app. Here is more information on how localStorage works. A very simle work flow will look something like the following:
if (localStorage.getItem("accountId") == null) {
// Show the user the sign up page
} else {
// Do not show sign up page
}

Kody R.
- 2,430
- 5
- 22
- 42
2
You can either use local storage or secure storage for storing some kind of token or something for the app.
During the startup of the app, you can check for the token and act accordingly.
secure storage cordova plugin https://github.com/Crypho/cordova-plugin-secure-storage
local storage cordova plugin https://cordova.apache.org/docs/en/latest/cordova/storage/storage.html
Hope this helps. :)

Bhanuka Mahanama
- 143
- 5
-
Thank you very much, additionaly a question. Is there a way to prevent a cordova app to lose the cookies and session information when closing the app? Or is this the recommended way to restore the session? – Playdome.io Apr 13 '17 at 10:31
-
1you may find this thread useful http://stackoverflow.com/questions/29960037/localstorage-vs-sessionstorage-vs-cookies . Plus I have seen local storage and secure storage as the common practice among the developers. – Bhanuka Mahanama Apr 13 '17 at 14:13