I'm encountering an issue and seeking some guidance. In my Angular application, I want to intercept every state change and redirect the user back to the login page if they are not authenticated. I am storing their encrypted sessionID in a cookie, checking if the cookie is undefined, and then directing the user accordingly. I plan to utilize the toState and toParams arguments in the future for user roles, but for now, let's focus on the current task.
Any advice or feedback would be greatly appreciated. Thank you in advance!
.run(($rootScope, $state, $cookies) => {
$rootScope.$on('$stateChangeStart', (evt, toState, toParams) => {
if(!$cookies.get('SessionID')){
evt.preventDefault();
$state.go('login');
}
})
})