|
@ -10,7 +10,7 @@ import axios from 'axios'; |
|
|
import { React, useState } from 'react'; |
|
|
import { React, useState } from 'react'; |
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
import { useDispatch, useSelector } from 'react-redux'; |
|
|
import { Redirect, useHistory } from 'react-router-dom'; |
|
|
import { Redirect, useHistory } from 'react-router-dom'; |
|
|
import { authLogin } from '../features/auth/authSlice'; |
|
|
|
|
|
|
|
|
import { authLogin, authLogout } from '../features/auth/authSlice'; |
|
|
|
|
|
|
|
|
function Login() { |
|
|
function Login() { |
|
|
const [email, setEmail] = useState(null); |
|
|
const [email, setEmail] = useState(null); |
|
@ -21,7 +21,7 @@ function Login() { |
|
|
|
|
|
|
|
|
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); |
|
|
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); |
|
|
if (isAuthenticated) return <Redirect to="/home" />; |
|
|
if (isAuthenticated) return <Redirect to="/home" />; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = e => { |
|
|
const handleSubmit = e => { |
|
|
if (!email | !password) { |
|
|
if (!email | !password) { |
|
|
toast({ |
|
|
toast({ |
|
@ -57,6 +57,7 @@ function Login() { |
|
|
dispatch(authLogin()); |
|
|
dispatch(authLogin()); |
|
|
history.push('/home'); |
|
|
history.push('/home'); |
|
|
} else { |
|
|
} else { |
|
|
|
|
|
dispatch(authLogout()); |
|
|
toast({ |
|
|
toast({ |
|
|
title: 'An error occurred', |
|
|
title: 'An error occurred', |
|
|
description: response.data.message, |
|
|
description: response.data.message, |
|
@ -67,6 +68,7 @@ function Login() { |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.catch(err => { |
|
|
.catch(err => { |
|
|
|
|
|
dispatch(authLogout()); |
|
|
toast({ |
|
|
toast({ |
|
|
title: 'An error occurred', |
|
|
title: 'An error occurred', |
|
|
description: 'Sorry, an error occurred on our side.', |
|
|
description: 'Sorry, an error occurred on our side.', |
|
|