diff --git a/client/src/api-service/apiConfig.ts b/client/src/api-service/apiConfig.ts index 7fa6459..ab5e0ae 100644 --- a/client/src/api-service/apiConfig.ts +++ b/client/src/api-service/apiConfig.ts @@ -58,9 +58,12 @@ const ApiConfig = { token: data.token }; } - if (response.status === 404) { + if (response.status === 403) { return new Error('Wrong username or password!'); } + if (response.status === 404) { + return new Error('Username not found!'); + } } catch (error) { if (typeof error === 'string') { diff --git a/client/src/views/Login/index.tsx b/client/src/views/Login/index.tsx index a372f35..69fd3eb 100644 --- a/client/src/views/Login/index.tsx +++ b/client/src/views/Login/index.tsx @@ -16,6 +16,7 @@ function Login(): JSX.Element { const navigate = useNavigate(); const [validated, setValidated] = useState(true); const [formInvalid, setFormInvalid] = useState(false); + const [errorMessage, setErrorMessage] = useState(''); /** * Handles the form submit button click event. @@ -35,8 +36,17 @@ function Login(): JSX.Element { } setFormInvalid(false); - await signIn(form.email.value, form.password.value); - goTo("/home"); + try { + await signIn(form.email.value, form.password.value); + goTo("/home"); + } catch (e) { + setFormInvalid(true); + if (typeof e === 'string') { + setErrorMessage(e); + } else if (e instanceof Error) { + setErrorMessage(e.message); + } + } }; /** @@ -60,7 +70,7 @@ function Login(): JSX.Element { {formInvalid ? ( - Invalid email or password. + { errorMessage } ) : null}