diff --git a/logout.js b/logout.js index 66841c7..2d88038 100644 --- a/logout.js +++ b/logout.js @@ -1,9 +1,6 @@ -//VARIBLES -myStorage = window.localStorage; -// //IF NOT LOGGED IN DON'T SHOW LOGOUT BUTTON -while (username === null) { - document.getElementById("logoutbutton").style.display = "none"; -} +// //VARIBLES +// myStorage = window.localStorage; +// allCookies = document.cookie; //LOGOUT FETCH FUNCTION @@ -17,33 +14,19 @@ async function logout() { body: JSON.stringify(sendLogoutInfo), }); document.querySelector("#errormessage").innerHTML = 'Logged out.' + document.getElementById("logoutbutton").style.display = "none"; localStorage.removeItem('username') username = null; loggedIn() } -//CHECKS TO SEE IF USERNAME MATCHES TOKEN -let tokenUpdate = window.setInterval(checkToken, 1000); +// // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT +// if (allCookies !== '' && myStorage.length === 0) { +// logout() +// } -async function checkToken() { - const response = await fetch(`api/token/${username}/`); - const matches = await response.json(); - - //YES THIS IS CONFUSING I KNOW. - if (matches.status === "fail") { - loggedOut() - } - - // IF NO USERNAME BUT HAS A TOKEN THEN LOGOUT - - if (matches.status === "ok" && myStorage.length === 0) { - logout() - } -} - -//AND IF THEY DON'T HAVE A TOKEN CLEARS THE LOCAL STORED USERNAME - -function loggedOut() { - localStorage.removeItem('username') - document.querySelector("#loggeduser").innerHTML = 'You are not logged in' -} \ No newline at end of file +// // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY. +// if (allCookies === '' && myStorage.length !== 0) { +// localStorage.removeItem('username') +// document.querySelector("#loggeduser").innerHTML = 'You are not logged in' +// } \ No newline at end of file