How to save a session in phoneGap

I cannot find a way to handle this. I developed one application for one page in PhoneGap, which is only a login module, after logging in I drop it on the website. Now the point is that I must also maintain login status. For example, if a user exits the application without exiting the system, then he should not get his login screen, he should go directly to the website.

In android, we can handle this using the general settings that I know, but I'm new to PhoneGap. Also, when the user presses the logout button, the “My Login” screen should appear on the screen (not that specific website login screen!).

I searched for it but did not find anything useful

+4
source share
3 answers

You can use localStorage since Nurdin said this is not the case.

Read more about this here. http://www.w3schools.com/html/html5_webstorage.asp

, so you have to set a condition to check if the user is logged in or not before the login page, i.e.

if(window.localStorage.getItem("loggedIn") == 1) {
// Logged In
// Redirect to first page after logged in.
}
else
{
// Redirect to login page.
}

On the login page after a successful login.

window.localStorage.setItem("loggedIn", 1);
window.localStorage.setItem("username", document.getElementsByName("usernametextbox").value);

etc..

On the logout page, clear this local storage.

window.localStorage.removeItem("loggedIn");
window.localStorage.removeItem("username");
+6
source

You can save login status and session id in sqlLite or LocalStorage. And when you start the application, you can check the values ​​in the repository that you used.

http://docs.phonegap.com/en/edge/cordova_storage_localstorage_localstorage.md.html

0

Use localStorageinstead sessionStorage. For more effective use, use sqlite. SessionStorage is only temporarily compared to localStorage. But sqlite is more persistent.

localStorage syntax

localStorage.userId

SessionStorage Syntax

sessionStorage.userId

Sqlite

https://github.com/brodysoft/Cordova-SQLitePlugin

0
source

Source: https://habr.com/ru/post/1570465/


All Articles