diff options
Diffstat (limited to 'frontend/pages/login.vue')
-rw-r--r-- | frontend/pages/login.vue | 15 |
1 files changed, 10 insertions, 5 deletions
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"; |