21 lines
602 B
JavaScript
21 lines
602 B
JavaScript
import React, {useContext, useEffect} from 'react';
|
|
import {AuthContext} from "../App";
|
|
import {logout} from "../auth";
|
|
import {Link} from "react-router-dom";
|
|
import {toast} from "react-toastify";
|
|
|
|
function Logout(props) {
|
|
const {authDispatch, authState} = useContext(AuthContext)
|
|
useEffect(() => {
|
|
if (authState.loggedIn) authDispatch({response: logout(authState.token)})
|
|
else toast.warn("You are not logged in!")
|
|
props.history.push("/")
|
|
})
|
|
|
|
return (
|
|
<div>You will soon be redirected. Click <Link to="/">here</Link> if you are not.</div>
|
|
);
|
|
}
|
|
|
|
export default Logout;
|