Reputation: 33
I am using $sessionStorage to store the user information after signing in , after all operations while logging out I need to clear session and clear cache.
I am able to set user info in $session but couldn't clear session while logging out. here is my code
if(data!=null && data.accessible == true){
$sessionStorage.user = JSON.stringify(data); //Storing user info in session
$sessionStorage.loggedIn = true;
$rootScope.loggedIn = true;
$rootScope.loggedInuserId = userName;
$rootScope.menuType=data.defaultMenuType;
$scope.operational=data.operational;
$scope.lifeCycle=data.lifeCycle;
$scope.qbot=data.qbot;
$scope.admin=data.admin;
if($scope.admin){
$state.go('admin');
$scope.menubar = false;
}
else if($scope.operational){
$state.go('dashboard');
$scope.var1=true;
}else if ($scope.lifeCycle){
$state.go('lifecycle');
$scope.menubar = false;
}else if ($scope.qbot){
$scope.menubar = false;
$state.go('qbot')
}
}else if(data!=null && data.accessible == false){
$rootScope.registereduser = true;
$rootScope.loggedIn = false;
}
Now I wanna clear session while logging out. Here is my Code
$scope.logout=function(){
$sessionStorage.clear();
$rootScope.loggedIn = false;
$rootScope.registereduser = false;
$rootScope.registration = false;
}
I have used $sessionStorage.clear() , $sessionStorage.remove().. but couldn't . Can anyone help on this?
Upvotes: 3
Views: 15837
Reputation: 3209
You are able to clear all data stored within sessionStorage if required.
In order to clear everything stored by your application within sessionStorage you should use the following:
$sessionStorage.empty();
See the link http://ghost.scriptwerx.io/angularjs-sessionstorage/
Upvotes: 2