$(".btn-logout").click(function() { 
  let token = getCookie('jwt_token');
  if(!token) {
    return
  }
  axios({
    method: 'post',
    url: 'https://www.choozmo.com:8887/logout_jwt',
    headers: { 
      'accept': 'application/json',
      'Authorization': `Bearer ${token}`
    },
    data: ''
    }).then(res => {
      console.log(res.data);
      if(res.data.msg == 'ok'){
        document.cookie = 'jwt_token=null';
      }
      window.location.href = 'index.html';
    }).catch(err => {
      console.log(err);
    });
});

function getCookie(name) {
  const value = `; ${document.cookie}`;
  const parts = value.split(`; ${name}=`);
  if (parts.length === 2) return parts.pop().split(';').shift();
}

