-1

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?

Playdome.io
  • 3,137
  • 2
  • 17
  • 34

2 Answers2

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. :)

  • 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
  • 1
    you 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