From 5a2a2db5e204d6dbc245f920751144e92b08b837 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Sun, 2 Jun 2024 23:04:42 +0200 Subject: [PATCH] Fixes: error handling on signup page #13 --- frontend/app/signup.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/frontend/app/signup.js b/frontend/app/signup.js index dab38ef..f5f2ec3 100644 --- a/frontend/app/signup.js +++ b/frontend/app/signup.js @@ -16,23 +16,28 @@ function SignupPage() { const { onSignin } = useAuth(); async function signin() { - if (pass1 == pass2) { - const res = await onSignin(username, email, pass1); - if (res.error) { - if (res.msg.message == "validation error") { - alert(res.msg.data.message); - } else { - alert(res.msg.message); - } - } - if (!res.error) { - alert("You have been successfully registered. Please Log In"); - router.replace("/login"); + if (pass1 != pass2) { + alert("Passwords are not same!"); + return; + } + + const res = await onSignin(username, email, pass1); + const data = await res.json(); + + if (res.status == 400) { + if (data.message == "validation error") { + alert(data.data.message); + } else { + alert("Something went wrong"); } return; } - alert("Passwords are not same!"); + if (res.status == 201) { + alert("You have been successfully registered. Please Log In"); + router.replace("/login"); + return; + } } return (