|
@ -2,27 +2,36 @@ import { Flex, Heading, Text } from "@chakra-ui/react"; |
|
|
import axios from "axios"; |
|
|
import axios from "axios"; |
|
|
import { useEffect } from "react"; |
|
|
import { useEffect } from "react"; |
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
import { Redirect } from "react-router-dom"; |
|
|
|
|
|
import { setCovidPositive } from "../features/auth/covidSlice"; |
|
|
|
|
|
|
|
|
import { Redirect, useHistory } from "react-router-dom"; |
|
|
|
|
|
import { authLogout } from "../features/auth/authSlice"; |
|
|
|
|
|
import { setCovidNegative, setCovidPositive } from "../features/auth/covidSlice"; |
|
|
|
|
|
|
|
|
function Lockout() { |
|
|
function Lockout() { |
|
|
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); |
|
|
const isAuthenticated = useSelector(state => state.auth.isAuthenticated); |
|
|
const isCovidPositive = useSelector(state => state.covid.isCovidPositive); |
|
|
const isCovidPositive = useSelector(state => state.covid.isCovidPositive); |
|
|
const dispatch = useDispatch(); |
|
|
const dispatch = useDispatch(); |
|
|
|
|
|
const history = useHistory(); |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
useEffect(() => { |
|
|
|
|
|
|
|
|
axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true }) |
|
|
axios.post(`${process.env.REACT_APP_API_URL}/covid`, {}, { withCredentials: true }) |
|
|
.then(res => { |
|
|
.then(res => { |
|
|
if(res.body.positivity){ |
|
|
|
|
|
|
|
|
if (res.data.covidPositive) { |
|
|
dispatch(setCovidPositive()); |
|
|
dispatch(setCovidPositive()); |
|
|
|
|
|
} else if (res.data.covidPositive === false) { |
|
|
|
|
|
dispatch(setCovidNegative()); |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
.catch(err => { |
|
|
.catch(err => { |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
if (err.response.status === 401) { |
|
|
|
|
|
dispatch(authLogout()); |
|
|
|
|
|
history.push("/login"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (e) { } |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}, [dispatch]); |
|
|
|
|
|
|
|
|
}, [dispatch, history]); |
|
|
|
|
|
|
|
|
if (!isAuthenticated) return <Redirect to="/login" />; |
|
|
if (!isAuthenticated) return <Redirect to="/login" />; |
|
|
if (!isCovidPositive) return <Redirect to="/home" />; |
|
|
if (!isCovidPositive) return <Redirect to="/home" />; |
|
|