import { useSelector } from "react-redux";
import { Navigate, useLocation } from "react-router-dom"

const RequireAuth = ({children}) => {
    const location = useLocation();
    const auth = useSelector(state => state.auth.user)

    if (!auth){
        return <Navigate to='/login' state={{from: location}} />
    }
    return children
}

export default RequireAuth