lundi 26 janvier 2015

Delaying template rendering for authentication check in Angular


Vote count:

0




So I've been trying to get this to work all day. Angular can cause a big security issue if you have static URL's that lead to content in conjunction with an authentication scheme. If an unregistered user visits the page, the content will flash on screen for a moment before redirecting to a safe location. I found this issue, searched extensively, and settled upon the resolve property in $routeConfig. Unfortunately, no matter what I do, it doesn't work. Code below:



$routeProvider.when('/dashboard/:id', {
templateUrl: 'js/partials/dashboard.html',
controller:'DashCtrl',
access: access.user,
resolve: {
login: function(authService) {
var promise = authService.isLoggedIn();
promise.then(function(data){
// We're in successfully
}).catch(function(err){
// ew, go away, redirect to login page
window.location = "login";
});
}
}
});


AuthService.isLoggedIn() looks like:



isLoggedin : function() {
return $http.get("users/session_check").then(function(result) {
if (result.data) {
if (user == undefined)
{
placeholderService.populatePlaceholders();
user = result.data;
}
return result.data;
} else {
return $q.reject("Please log in.");
}
});
}


No matter what, the view flashes. I have ng-cloaks on the page, nothing. I have no idea what else to do, but this has become downright infuriating.



asked 38 secs ago







Delaying template rendering for authentication check in Angular

Aucun commentaire:

Enregistrer un commentaire