I am in the middle of making an app using a PHP web service to log users in/authenticate their credentials.
I am using localStorage (part of phonegaps local storage API) to ensure the user doesnt have to keep logging in when they open the app. This is done by storing the username and password on local storage and checking it when the app opens. If they feel the need to log out I have a simple logout button binded to a tap event which clears their local storage.
$( '#logout' ).live( 'tap',function(event){
window.localStorage.clear();
$.mobile.changePage("#loginPage", {transition: "none"});
});
BUT… when logged out, they are still able to click the back button on the phone and get into the secure area, which doesnt make sense because the “welcome, (username)” part is all messed up etc…
Im wondering if there is a way to ensure that what ever page they open does some sort of check to make sure theyre logged in??
Bind into the
pagebeforeshowevent of the pages to check if the user is logged on – check if credentials are present in local storage.If user is not logged on you can either call
preventDefaultto stop thepageChangeor better redirect the user to a loggedOffPage by modifying thetoPagepassed into the handler.Refer the
Page change eventssection on JQM Events page.