From e335601ab8a5d088a655896a74595746c59d5c02 Mon Sep 17 00:00:00 2001 From: Edward Tirado Jr Date: Sun, 6 Apr 2025 15:42:57 -0500 Subject: [PATCH] updated login --- src/pages/index.vue | 88 ++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 33 deletions(-) diff --git a/src/pages/index.vue b/src/pages/index.vue index aaafffd..03ec09c 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -2,31 +2,53 @@

Login

-
+
-
- +
+
-
- +
+
- +
- +
-
@@ -36,29 +58,31 @@ export default { methods: { login: async function (e) { const config = useRuntimeConfig(); - e.preventDefault() - document.getElementById("password-incorrect").classList.add("hidden") + e.preventDefault(); + document.getElementById("password-incorrect").classList.add("hidden"); let username = document.getElementById("username").value; let password = document.getElementById("password").value; - let response = await fetch(`${config.public.apiURL}/auth/login`, { + let response = await fetch(`${config.public.apiURL}/auth/login/`, { method: "POST", - body: JSON.stringify({username: username, password: password}), - headers: {"Content-type": "application/json"} + body: JSON.stringify({ username: username, password: password }), + headers: { "Content-type": "application/json" }, }) - .then(response => { - if (!response.ok) { - document.getElementById("password-incorrect").classList.remove("hidden") - return false; - } + .then((response) => { + if (!response.ok) { + document + .getElementById("password-incorrect") + .classList.remove("hidden"); + return false; + } - return response.json(); + return response.json(); - //window.location = "/admin" - }) - .catch(err => { - return false - }) + //window.location = "/admin" + }) + .catch((err) => { + return false; + }); if (response) { let token = useCookie("token", { @@ -66,19 +90,17 @@ export default { }); token.value = response.token; - return navigateTo("/admin") + return navigateTo("/admin"); } - } + }, }, mounted() { let token = useCookie("token"); if (token.value) { - navigateTo("/admin") + navigateTo("/admin"); } - } -} + }, +}; - \ No newline at end of file +