Rutwick Gangurde
Rutwick Gangurde

Reputation: 4912

VueJS - Erase cookie set by the backend server via a logout component

I have a VueJS UI that runs on the port 8080, whereas my Node server which handles the auth runs on 8082. After login our Auth server redirects back to the UI, and sets the required session cookie. I need to set this cookie to null in my frontend when I click the Logout button, before redirecting to the server Logout action which takes care of the backend details.

I am not able to access document.cookie, or delete the cookie using Vue.cookie. Both of these return the cookie value as null. How would I do it?

Upvotes: 6

Views: 9904

Answers (1)

Saddy
Saddy

Reputation: 1581

To properly delete a cookie, do the following:

function delete_cookie(name) {
  document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}

Source

Upvotes: 8

Related Questions