0

I am using angularjs with spring security I have the following code in my app.js

     function run($rootScope, $location, $cookieStore, $http) {
            // keep user logged in after page refresh
            $rootScope.globals = $cookieStore.get('globals') || {};
            if ($rootScope.globals.currentUser) {
                $http.defaults.headers.common['Authorization'] = 'Basic ' + $rootScope.globals.currentUser.authdata; // jshint ignore:line
            }
     }

when I press on logout I have to delete the current user $rootScope.globals.currentUser so the application work

how can I do that I tried to delete it by java code

@RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logout(HttpServletRequest request, HttpServletResponse response) {

        HttpSession session= request.getSession(false);
        SecurityContextHolder.clearContext();
             session= request.getSession(false);
            if(session != null) {
                session.invalidate();
            }
            for(Cookie cookie : request.getCookies()) {
                cookie.setMaxAge(0);
            }
        return "redirect:/j_spring_security_logout";
    }
but It didn't work
Belal Othman
  • 231
  • 3
  • 12
  • Obviously, `$rootScope.globals.currentUser = null;` but I guess it's not your question ... Could you rephrase it please ? –  Nov 22 '16 at 14:05
  • http://stackoverflow.com/questions/26607856/how-to-remove-all-cookies-in-angularjs Does this work? – Jānis Jirgensons Nov 22 '16 at 14:06

1 Answers1

0

You can simply use angular $cookies service and remove it like this:

$cookies.remove('coockieName');
Sahbaz
  • 1,242
  • 4
  • 17
  • 39