diff --git a/frontend/src/components/Login.tsx b/frontend/src/components/Login.tsx index c61a0a0d..0341b9c5 100644 --- a/frontend/src/components/Login.tsx +++ b/frontend/src/components/Login.tsx @@ -1,7 +1,7 @@ import { useState, ChangeEvent, FormEvent, useEffect } from 'react' import { useTryLoginMutation, setUser } from '../redux/userReducer' import { useDispatch } from 'react-redux' -import { Box, Button, CircularProgress, Container, Stack, TextField, Typography } from '@mui/material' +import { Box, Button, CircularProgress, Container, Stack, TextField } from '@mui/material' import { useLocation, useNavigate } from 'react-router-dom' import { api } from '../redux/api' import { useNotify } from '@/hooks/notification' @@ -11,7 +11,7 @@ export const Login = () => { const [password, setPassword] = useState('') const [usernameError, setUsernameError] = useState('') const [passwordError, setPasswordError] = useState('') - const [loginMutation, { data, isLoading, isError }] = useTryLoginMutation() + const [loginMutation, { data, isLoading }] = useTryLoginMutation() const dispatch = useDispatch() const navigate = useNavigate() const location = useLocation() @@ -39,44 +39,38 @@ export const Login = () => { } setUsernameError('') setPasswordError('') - const result = await loginMutation({ username, password }).unwrap() + try { + const result = await loginMutation({ username, password }).unwrap() + notify('Logged in!') + dispatch(setUser(result)) - if (!result) { - notify('Login unsuccessful', 'error') - return - } - notify('Logged in!') - dispatch(setUser(result)) - - // Reset api cache, so that we won't show guest data (which would have omitted items) to a logged user - dispatch(api.util.resetApiState()) - if (result.isFirstLogin) { - navigate(`/person/user-page`) - } else { - navigate('/') + // Reset api cache, so that we won't show guest data (which could have omitted items) to a logged user + dispatch(api.util.resetApiState()) + if (result.isFirstLogin) { + navigate(`/person/user-page`) + } else { + navigate('/') + } + } catch (e: unknown) { + if (e && typeof e === 'object' && 'status' in e && e.status === 403) { + notify('Login unsuccessful. Please check credentials.', 'error') + return + } + notify('Login unsuccessful for unknown reason', 'error') } } return ( - {loginHadExpired ? ( -

- Your login expired. Please login again. -

- ) : ( - <> -

- Welcome! The users from the old Now Database application work here. If you are logging in this new - version for the first time, you can use your password of the old application. -

-

- However, upon first login, please change your password in this application. After changing it, the - new password will be used for this new version, but the{' '} - old version will still work with your old password. -

- - )} +

+ Welcome! The users from the old Now Database application work here. If you are logging in this new + version for the first time, you can use your password of the old application. +

+

+ However, upon first login, please change your password in this application. After changing it, the new + password will be used for this new version, but the old version will still work with your old password. +

void login(event)}> @@ -105,11 +99,6 @@ export const Login = () => { - - - {isError && 'Login failed. Please check username and password.'} - -
{(isLoading || data) && } diff --git a/frontend/src/components/Person/Tabs/PersonTab.tsx b/frontend/src/components/Person/Tabs/PersonTab.tsx index 5d707318..6f6915fe 100644 --- a/frontend/src/components/Person/Tabs/PersonTab.tsx +++ b/frontend/src/components/Person/Tabs/PersonTab.tsx @@ -45,7 +45,6 @@ export const PersonTab = () => { {currentUser.isFirstLogin && ( -

Please change your password!

Changing your password here will only set the password for this new version. The old application will still work with your old password.