I am trying to create a session redirect if the user is not logged in. The code is working as I expected. However, when I take a look on the console, An error occurs (as in indicated in the title). I can not seem to fix this and I need some help.
var domainName = window.location.href;
var domainName = domainName.split("/");
var domainName = domainName[0] + "//" + domainName[2];
var app = angular.module("app", []);
app.run(run);
run.$inject = ["$window", "$rootScope", "$cookies"];
function run($window, $rootScope, $cookies){
// Runs everytime the URL changes
$rootScope.$on('$locationChangeStart', function(event, current, previous) {
// If the user is not logged-in and is not trying to access the register or log-in, It will go back to the log-in page
// if(!$cookies.get('user') && current != domainName+"/#/"){
if(current != domainName+"/#/"){
$window.location.href = domainName+"/#/";
// Create a scope that will remind the users regarding the session
// $rootScope.sessionError = "Please Enter Exam Code before taking the exam";
}
});
}