From d875ce398f0f4a4438cb06e7976488a9551be390 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 25 Jul 2021 11:14:45 -0700 Subject: [PATCH] Frontend: checking for username and token mismatch --- chat.js | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/chat.js b/chat.js index fb61f3b..6efd956 100644 --- a/chat.js +++ b/chat.js @@ -12,17 +12,21 @@ form.addEventListener("submit", async function (event) { formMessage = formData.get('message').toString(); - //KINDA UNNECESSARY - //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE. - const response = await fetch(`api/token/${username}/`); - const matches = await response.json(); - - //YES THIS IS CONFUSING I KNOW. - if (matches.status === "ok") { - sendMessage() - } else { - document.querySelector("#errormessage").innerHTML = 'Username and token mismatch. Try logging in again.' - } + //KINDA UNNECESSARY + //CHECKS TO SEE IF THE PERSON IS LOGGED IN IN ORDER TO SEND A MESSAGE. + const response = await fetch(`api/token/${username}/`); + const matches = await response.json(); + + //YES THIS IS CONFUSING I KNOW. + if (matches.status === "ok") { + sendMessage() + } else { + const mismatch = 'Username and token mismatch. Try logging in again.' + printText(mismatch.bold()) + logout() + localStorage.removeItem('username') + } + }) //SEND MESSAGE FETCH FUNCTION @@ -86,4 +90,11 @@ function loggedIn() { loggedIn() -//REVIECE USERS PRONOUNS \ No newline at end of file +//REVIECE USERS PRONOUNS + +async function getPronouns() { +const response = await fetch(`api/users/${username}/`); +const data = await response.json(); +pronouns = data.pronouns +return pronouns; +} \ No newline at end of file