Open wesleyegbertsen opened 8 years ago
Currently it basically checks on every $routeChangeStart event with this.
$rootScope.$on("$routeChangeStart", function(args){
$scope.isLoggedIn();
});
This is the isLoggedIn function.
$scope.isLoggedIn = function () {
UserService.isLoggedIn(function (data) {
if (data) {
if (data.success) {
$scope.user = data.user;
enableUserDropDown();
} else {
$scope.user = {};
$location.url("/login");
}
} else {
$scope.user = {};
$location.url("/login");
}
});
};
This works and all to show the right view to the user based on the PHP Session in the back-end. But what I meant with it's a bit wonky. Is that it flashes the content a bit, because when you go to the home page you have the overview of your shows. The $routeChangeStart event was fired and in that event it checks with the PHP back-end api, if the user is logged in based of a PHP Session. the isLoggedIn function in the events finishes and reports if the user is logged in. If not it will redirect itself to the login page. And this is where the fast flashing of the home page content comes in play.
A research is needed for a better way of implementing client-side authentication & authorisation for the Angular routes with a back-end api.
Client-side authentication & authorisation is a bit wonky now, this needs to be improved.