From d40af87c46ee62ffb2c7512f72077069aec7e7e2 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Mon, 3 Jun 2024 16:19:32 +0200 Subject: [PATCH] Fixes: error handling on login page #13 --- frontend/app/context/AuthContext.js | 4 ++-- frontend/app/login.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/app/context/AuthContext.js b/frontend/app/context/AuthContext.js index 79dcd4a..3b4da17 100644 --- a/frontend/app/context/AuthContext.js +++ b/frontend/app/context/AuthContext.js @@ -90,7 +90,7 @@ export function AuthProvider({ children }) { }); if (resUser.status != 200) { - throw Error("user does not have user data"); + throw Error("Username or password is incorrect!"); } const userData = await resUser.json(); @@ -104,7 +104,7 @@ export function AuthProvider({ children }) { await storageUtil.setItem(TOKEN_KEY, loginData.data.jwt); } catch (err) { console.error("Failed to log in", err); - return { error: true, msg: err.res }; + return { error: true, msg: err }; } } diff --git a/frontend/app/login.js b/frontend/app/login.js index e1e69ac..60ea953 100644 --- a/frontend/app/login.js +++ b/frontend/app/login.js @@ -20,8 +20,12 @@ function LoginPage() { } }, [authState.authenticated]); - function login() { - onLogin(email, pass); + async function login() { + const res = await onLogin(email, pass); + if (res !== undefined && res.error === true) { + alert(res.msg); + return; + } } return (