I have a SPA using JWT (json web tokens) for authorization to the api. The problem is when they hit refresh on the browser after being logged in I need to verify the token is still valid via an ajax request and then continue loading the SPA. I added this to the .run() which kind of works, but since my navigation changes if they are logged in, the page loads before the token is verified, and looks wrong. I'm new to angular, but guess this could be done with a promise?
// handle refreshing browser
if ($window.sessionStorage.token && !AuthenticationService.isLogged()) {
UserService.verify().success(function (data) {
AuthenticationService.setLogged(true);
}).error(function () {
delete $window.sessionStorage.token;
$state.transitionTo('app.login');
});
}