1

My cookie changes whenever I try to logout, at first I will get a cooking when login successfully , then when trying to logout my cookie changes and logout will fail. Below is my code:

Code for login:

$.ajax({
  method: "POST",
  url: unicornRes("login"),
  contentType: "application/json",
  data: JSON.stringify({
    userAcc: email,
    userPwd: password
  })
}).fail((err)=> {
  console.log(err);
  this.setState({loginInputErr: "loginFail", password: ""});
}).done((data) => {
  console.log("login Mode:", data.message);
  localStorage.setItem("unicorn", data.message);
  $.ajaxSetup({
    xhrFields: {
      withCredentials: true
    }
  });
  router.push('/');
});

Code for logout:

$.ajax({
  method: "POST",
  url: unicornRes("logout")
}).fail((err)=> {
  console.log(err);
}).done((data) => {
  localStorage.setItem("unicorn", data.message);
  router.push('/login');
});

Cookie changes from

3A6pkDbK4JNrkwevjH (part of cookie)

to:

3ACek0_Zp2HVUtz5itimy8eW_8hChv3jeq

Why is it changing? I need the cookie to be the same for logout.

1 Answers1

0

Maybe you need credentials,

Cross domain jQuery ajax call with credentials

And have a check at this;

https://www.html5rocks.com/en/tutorials/cors/#disqus_thread

Community
  • 1
  • 1
JerryKo
  • 384
  • 7
  • 25