Compare commits

...

2 Commits

Author SHA1 Message Date
Luna c826b6b5db Frontend: updated logout. 2021-07-25 11:15:00 -07:00
Luna d875ce398f Frontend: checking for username and token mismatch 2021-07-25 11:14:45 -07:00
2 changed files with 32 additions and 21 deletions

35
chat.js
View File

@ -12,17 +12,21 @@ form.addEventListener("submit", async function (event) {
formMessage = formData.get('message').toString(); formMessage = formData.get('message').toString();
//KINDA UNNECESSARY //KINDA UNNECESSARY
//CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE. //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE.
const response = await fetch(`api/token/${username}/`); const response = await fetch(`api/token/${username}/`);
const matches = await response.json(); const matches = await response.json();
//YES THIS IS CONFUSING I KNOW. //YES THIS IS CONFUSING I KNOW.
if (matches.status === "ok") { if (matches.status === "ok") {
sendMessage() sendMessage()
} else { } else {
document.querySelector("#errormessage").innerHTML = 'Username and token mismatch. Try logging in again.' const mismatch = 'Username and token mismatch. Try logging in again.'
} printText(mismatch.bold())
logout()
localStorage.removeItem('username')
}
}) })
//SEND MESSAGE FETCH FUNCTION //SEND MESSAGE FETCH FUNCTION
@ -86,4 +90,11 @@ function loggedIn() {
loggedIn() loggedIn()
//REVIECE USERS PRONOUNS //REVIECE USERS PRONOUNS
async function getPronouns() {
const response = await fetch(`api/users/${username}/`);
const data = await response.json();
pronouns = data.pronouns
return pronouns;
}

View File

@ -20,13 +20,13 @@ async function logout() {
loggedIn() loggedIn()
} }
// // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT // IF THERE IS A TOKEN BUT NO USERNAME LOGOUT
// if (allCookies !== '' && myStorage.length === 0) { if (allCookies !== '' && myStorage.length === 0) {
// logout() logout()
// } }
// // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY. // IF THERE IS NO COOKIE BUT A USERNAME GET RID OF USERNAME LOCALLY.
// if (allCookies === '' && myStorage.length !== 0) { if (allCookies === '' && myStorage.length !== 0) {
// localStorage.removeItem('username') localStorage.removeItem('username')
// document.querySelector("#loggeduser").innerHTML = 'You are not logged in' document.querySelector("#loggeduser").innerHTML = 'You are not logged in'
// } }