lilachat-frontend/logout.js

32 lines
917 B
JavaScript
Raw Normal View History

2021-07-24 19:58:27 +00:00
// //VARIBLES
// myStorage = window.localStorage;
// allCookies = document.cookie;
2021-07-23 14:30:24 +00:00
//LOGOUT FETCH FUNCTION
async function logout() {
2021-07-24 14:10:41 +00:00
let sendLogoutInfo = { "name": username }
fetch('/api/logout/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
2021-07-23 14:30:24 +00:00
},
2021-07-24 14:10:41 +00:00
body: JSON.stringify(sendLogoutInfo),
});
document.querySelector("#errormessage").innerHTML = 'Logged out.'
2021-07-24 19:58:27 +00:00
document.getElementById("logoutbutton").style.display = "none";
2021-07-24 14:10:41 +00:00
localStorage.removeItem('username')
username = null;
loggedIn()
2021-07-23 19:41:55 +00:00
}
2021-07-24 18:27:09 +00:00
2021-07-24 19:58:27 +00:00
// // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
// if (allCookies !== '' && myStorage.length === 0) {
// logout()
// }
2021-07-24 18:27:09 +00:00
2021-07-24 19:58:27 +00:00
// // 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'
// }