const btnLoginPage = document.querySelector('.btn-login'); const btnUserProfile = document.querySelector('.btn-userProfile'); const btnLogout = document.querySelector('.btn-logout'); function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } function renderView() { axios({ method: 'get', url: 'http://www.choozmo.com:8887/user_profile', headers: { 'accept': 'text/html', 'Authorization' : `Bearer ${getCookie('jwt_token')}` } }).then(res => { console.log(res); }).catch(err => { console.log(err); }) } renderView(); function checkLogin() { let token = getCookie('jwt_token'); if(token) { btnLoginPage.style.display = 'none'; btnLogout.style.display = 'block'; btnUserProfile.style.display = 'block'; } else { window.location.href = 'login.html'; btnLoginPage.style.display = 'block'; btnLogout.style.display = 'none'; btnUserProfile.style.display = 'none'; } } checkLogin();