Can't delete cookie with AngularJS's $cookies

前端 未结 3 1640
遇见更好的自我
遇见更好的自我 2021-01-17 09:28

My web app is made so that when a user logs in the server adds a Set-Cookie header to the response, like this:

Set-Cookie:JSESSIONID=1; Path=/myApp/; Secure

3条回答
  •  情深已故
    2021-01-17 10:07

    The answer that you gave in the update seems to be correct: Angular $cookieStore can only work on cookies whose path value is the same as the current path.

    The way to trick it is to use the solution given by ajspera on this issue:

    
      
    
    

    Simply add to your head element of the HTML, and at that point it works.

    The alternative solution is to set the path of the cookie using the server that sent it. In Node.js Express that looks like

    res.cookie('specialCookie', 'special!', {path: '/myApp'});
    

    Note that for me it seems like $cookieStore strips out the trailing slash, so you may need to try it both ways.

提交回复
热议问题