I have an app in phonegap (pure js, html, css) where user signs in and then it has access to some aditional sites. My question is how to save his personal data or his session. There is no php involved for sending cookie or handling sessions. Everything need to be saved in JS (jQuery). How can I do this?
Share
You can use
HTML5feature Local StorageFor eg;
When user logs in, set one variable as
isAuthenticatedin your local storageBy default, it will be 0, on successful login, set it to 1.
On Successful login
And whenever you want to check user’s authenticity, simply compare value of
isAuthenticatedvariable from Local Storage.var isLoggedIn = localStorage.getItem(‘isAuthenticated’);
UPDATE
If you are storing javascript objects then
Convert your object into
stringusingJSON.stringifyand then store it into the local storage.While retrieving
castthatstringback into thejavascript objectusingJSON.parseLooking at the local storage documentation, the functionality seems to be limited to handle only string key/value pairs.
You can take a look at the documentation here
Apple
Mozilla
PS : Phonegap has nothing to do with working of local storage or any other HTML feature. Phonegap is just a middleware that facilitates communication between your device hardware and your javascript/html code.