I have seen many posts on this topic but things are not still very clear to me.
I have an angular app talking to a loopback 2 server.
A user authenticates through this controller :
.controller('AuthLoginController', ['$scope', 'AuthService', '$state',
function($scope, AuthService, $state) {
$scope.user = {
email: '',
password: '',
firstName: '',
lastName:''
};
$scope.login = function() {
AuthService.login($scope.user.email, $scope.user.password, $scope.user.firstName, $scope.user.lastName)
.then(function() {
$state.go('/');
});
};
}])
and through this service (factory):
.factory('AuthService', [ 'Client','$q', '$rootScope', function(Client, $q,
$rootScope) {
function login(email, password) {
return Client
.login({email: email, password: password})
.$promise
.then(function(response) {
$rootScope.currentUser = {
id: response.user.id,
tokenId: response.id,
email: email
};
});
}
The login process is ok. I can show some menus with
<li ng-show="currentUser">
and the appropriate
in ui-router.
Once logged in, I have
$LoopBack$accessTokenId BJD38Vo0BHnIvAZ2c54ZBrnNc2zo7f26AsEJGGIO0qCrTXfMSezpJkNvyiohMXlP
in my local storage.
My problem is :
When I do a refresh on a page (which is angular) defined in ui-router, the local storage persists in the browser cache but my page is unreachable (Error http 404).
The Token is still in the cache.
I do not understand what happens.
Any help would be really appreciated.
Kind Regards