I'm currently working on a web application using the AngularJS framework for the frontend. I need to restrict users from navigating to any page other than the login and registration pages on my site. However, my current code is blocking access to the registration page as well. Below is the snippet of my code. How can I modify it to allow users to navigate only to the login and registration pages when they are not logged in.
.run(function ($rootScope, $state, AuthService, AUTH_EVENTS) {
$rootScope.$on('$stateChangeStart', function (event,next, nextParams, fromState) {
if ('data' in next && 'authorizedRoles' in next.data) {
var authorizedRoles = next.data.authorizedRoles;
if (!AuthService.isAuthorized(authorizedRoles)) {
event.preventDefault();
$state.go($state.current, {}, {reload: true});
$rootScope.$broadcast(AUTH_EVENTS.notAuthorized);
}
}
if (!AuthService.isAuthenticated()) {
if (next.name !== 'login') {
event.preventDefault();
$state.go('login');
}
}
});