diff --git a/login.js b/login.js index 258ed71..ae58623 100644 --- a/login.js +++ b/login.js @@ -9,31 +9,16 @@ form.addEventListener("submit", async function(event) { uname = formData.get('uname'); pin = formData.get('pin'); - try { - const loginInfo = await loginFetch(); - - if (loginInfo === "pin matches") { - login() - } else if (loginInfo === "Incorrect pin" || loginInfo === `User ${uname} does not exist.`) { - incorrectLogin() - } - } catch { - document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.' + const response = await fetch(`/users/${uname}/${pin}`); + const loginInfo = await response.json(); + + if (loginInfo.status === "ok") { + login() + } else { + incorrectLogin() } }) -async function loginFetch() { - const rawResponse = await fetch(`/api/users/${uname}/${pin}`, { - // credentials: "include", - method: 'GET', - headers: { - 'Accept': 'text/plain' - }, -}); -const content = await rawResponse.text(); -return content -} - function login() { console.log('You have logged in!') document.querySelector("#username").innerHTML = `${uname}` diff --git a/loginchange.js b/loginchange.js index 466beb2..561ca6f 100644 --- a/loginchange.js +++ b/loginchange.js @@ -55,7 +55,6 @@ async function loginChange() { const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, { method: 'POST', headers: { - 'Accept': 'text/plain' }, body: "" }); diff --git a/register.js b/register.js index fa9f3d6..227f450 100644 --- a/register.js +++ b/register.js @@ -45,7 +45,6 @@ async function register() { const rawResponse = await fetch(`/api/register/${uname.toString().toLowerCase()}/${pin.toString()}/${pronouns.toString().toLowerCase().replace("/", ".")}`, { method: 'POST', headers: { - 'Accept': 'text/plain' }, body: "" });