summaryrefslogtreecommitdiff
path: root/frontend/pages/login.vue
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2025-04-03 12:36:34 +0200
committerSanto Cariotti <santo@dcariotti.me>2025-04-03 12:36:34 +0200
commit0d987f5c97cc8c0e205193ef8c67745ac981d5bf (patch)
tree8cee10db15c6b36abee89663fe1c7159a6b4d658 /frontend/pages/login.vue
parenta9b84f3f3b1d92335188d43048587e32e0921079 (diff)
Fix login and register
Diffstat (limited to 'frontend/pages/login.vue')
-rw-r--r--frontend/pages/login.vue15
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";