Login user Authentication and localstorage



i have implemented login system on my app.i am storing auth token on local storage.everything work fine once login is ok.
but every time i close the app and opens, login page pops up.how do i bypass login page when the user token is already exist on local storage.

my app structure goes like this:loginpage–>welcome page–>home page


if users token exists on local storage,i want to forward the page to welcome page.how do i implement this.

can someone please help me on this?


When i exit the app using navigator.app.exit on condition with out Logout,Again when i opened the app my account is going to login page?

put this in your app.js

if(window.localStorage['auth']) {


Hi Sjerd

It didnt work.it is throwing error.where should i put this code…run or .config



At the config before you define your states with $stateprovider

starter.config(function($stateProvider, $urlRouterProvider,$httpProvider,	$ionicConfigProvider) {


if(window.localStorage['auth']) {



Hi sjerd

Thanks a lot for your reply.

I am getting error if i add ionicconfigprovider inside function


which version of the ionic library do you use?


Hi Djerd

I am using V1.1.13.



try removing the $ionicConfigProvider parameter And the $ionicConfigProvider.prefetchtempaltes(false) statement from your code, it isn’t neccesaary for this to run.


Hi sjerd

Didnt work out bro :frowning: .Is this works for you.infact i cannot even add any parameters on .config function.everything is showing as error as showed you on image.



Try this on your app.js

.run(function ($ionicPlatform, $rootScope, User, $location) {
    $ionicPlatform.ready(function () {

        function(event, toState, toParams, fromState, fromParams){
            if (User.getCurrentUser() == null) {


Hi Pavei

Works Great!!!.Thank you thank you for your help.



hey @ashique can you share your login system? got a project that needs one. Thanks.

Problem with Auth state and redirect

check this out : apk and test it.

If this is what you’re looking for you can checkout both the client side code at : https://github.com/malikov/Authenticate.me-client-cordova-ionic

And the server side code at : https://github.com/malikov/Authenticate.me-Node-Server

Best of luck


Hey vmaliko

This is what exactly i was looking for…Thanks a lot bro.



Easiest way to do this would be to use https://github.com/gsklee/ngStorage to store the token in your model. Take a look at this project https://github.com/sathishc/localreads for a token based authentication solution. The Ionic app can be found at https://play.google.com/store/apps/details?id=com.squareprism.localreads.ver1


Ye works great for me ashique i can do all kinds of stuff with my config :o


you’re welcome, let me know how this works out for you or if you have questions.



If the run block I need to use a service (which makes an http.get), that is correct operation, the response of the service must come before continue with the routing.
As implemented using this scheme stateChangeStart?

I try to use the service outside in run since achieved with use at startup, not on each subsequent routing. But without the service response, continuous. That is a problem of asynchronism between the service and routing.

Alternatives? Some example of login at an external server ($ http) not only localStorage?


Hi @sjerd


hiii guys, i am aswin … i am also facing a same trouble… i created a app and launched in playstore… user felt struggle to give numerous login when close my application… now i blind to solve this problem… Give some ideas and suggestion to fix this problem