import { FC, PropsWithChildren, useContext } from 'react'
import { useLocation, Navigate } from 'react-router-dom';
import { Context } from "../../main"
import { observer } from "mobx-react-lite"

const OnlyUnauthorized: FC<PropsWithChildren> = observer(({children}) => {

    const {store} = useContext(Context);
    const location = useLocation();

    if (store.isAuth) {
        return <Navigate to="/" state={{ from: location }} replace />;
    }

    return children;
})

export default OnlyUnauthorized;