ReferenceError: token is not defined
<p>i've been following login tutorial with authentication in ionic. but when i try run the program and login, the error is :</p>

<blockquote>
  <p>ReferenceError: token is not defined
      at storeUserCredentials (services.js:16)
      at services.js:46
      at Object.login (services.js:44)</p>
</blockquote>

<p>anyone can help me please? this is my service :</p>

<pre><code>app.service('AuthService', function($q, $http, USER_ROLES){
    var LOCAL_TOKEN_KEY = 'yourTokenKey';
    var username = '';
    var isAuthenticated = false;
    var role = '';
    var authToken;

    function loadUserCredentials() {
        var token = window.localStorage.getItem(LOCAL_TOKEN_KEY);
        if (token) {
            useCredentials(token);
        }
    }

    function storeUserCredentials(){
        window.localStorage.setItem(LOCAL_TOKEN_KEY, token);
        useCredentials(token);
    }

    function useCredentials(token){
        username = token.split('.')[0];
        isAuthenticated = true;
        authToken = token;

        if (username == 'admin') {
            role = USER_ROLES.admin
        }
        if (username == 'user') {
            role = USER_ROLES.public
        }

        $http.defaults.header.common['X-Auth-Token'] = token;
    }

    function destroyUserCredentials(){
        authToken = undefined;
        username = '';
        isAuthenticated = false;
        $http.defaults.header.common['X-Auth-Token'] = undefined;
        window.localStorage.removeItem(LOCAL_TOKEN_KEY);
    }

    var login = function(name, pw){
        return $q(function(resolve,reject){
            if ((name == 'admin' &amp;&amp; pw == '1') || (name =='user' &amp;&amp; pw == '1')){
                storeUserCredentials(name +'.yourServerToken');
                resolve('Login Success');
            } else {
                reject('Login Failed');
            }
        });
    };

    var logout = function(){
        destroyUserCredentials();
    };

    var isAuthorized = function(authorizedRoles){
        if (!angular.isArray(authorizedRoles)){
            authorizedRoles = [authorizedRoles];
        }
        return (isAuthenticated &amp;&amp; authorizedRoles.indexOf(role))
    };

    loadUserCredentials();

    return {
        login : login,
        logout : logout,
        isAthorized : isAuthorized,
        isAuthenticated : function() {return isAuthenticated;},
        username : function() {return username;},
        role : function(){return role;}
    };
})

.factory('AuthInterceptor', function ($rootScope, $q, AUTH_EVENTS) {
  return {
    responseError: function (response) {
      $rootScope.$broadcast({
        401: AUTH_EVENTS.notAuthenticated,
        403: AUTH_EVENTS.notAuthorized
      }[response.status], response);
      return $q.reject(response);
    }
  };
})

.config(function ($httpProvider) {
  $httpProvider.interceptors.push('AuthInterceptor');
});
</code></pre>