Frontend: checking for username and token mismatch

main
Luna 2021-07-25 11:14:45 -07:00
parent 5543b1e8c5
commit d875ce398f
1 changed files with 23 additions and 12 deletions

13
chat.js
View File

@ -21,8 +21,12 @@ form.addEventListener("submit", async function (event) {
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
@ -87,3 +91,10 @@ 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;
}