From 0d987f5c97cc8c0e205193ef8c67745ac981d5bf Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Thu, 3 Apr 2025 12:36:34 +0200
Subject: Fix login and register

---
 frontend/pages/login.vue | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

(limited to 'frontend/pages/login.vue')

diff --git a/frontend/pages/login.vue b/frontend/pages/login.vue
index 0be0372..5fdb689 100644
--- a/frontend/pages/login.vue
+++ b/frontend/pages/login.vue
@@ -83,7 +83,7 @@ const handleSubmit = async (event) => {
     try {
         error.value = null;
         isLoading.value = true;
-        fetch(`${config.public.apiBase}/auth/login`, {
+        await fetch(`${config.public.apiBase}/auth/login`, {
             method: "POST",
             headers: {
                 "Content-Type": "application/json",
@@ -92,23 +92,28 @@ const handleSubmit = async (event) => {
                 username: username.value,
                 password: password.value,
             }),
-        }).then((response) => {
+        }).then(async (response) => {
+            const body = await response.json();
             if (response.status != 200) {
                 toast.add({
                     title: "Login Failed",
-                    description: response.body,
+                    description: body.error,
                     color: "error",
                 });
             } else {
                 toast.add({
                     title: "Login Successful",
-                    description: "You have been successfully logged in.",
+                    description: "You have been successfully logged in",
                     color: "success",
                 });
+
+                localStorage.setItem("token", body.token);
+                setTimeout(() => {
+                    window.location.href = "/play";
+                }, 1000);
             }
         });
     } catch (err) {
-        console.error("Login failed:", err);
         error.value =
             err.response?.data?.message || "An error occurred during login";
 
-- 
cgit v1.2.3-71-g8e6c

