/**
 * @file AuthRequired.js
 * @author Radim Buráň (xburan03@stud.fit.vutbr.cz)
 */

import {useAuth} from "../services/AuthMiddleware";
import {Navigate, useLocation} from "react-router-dom";

function AuthRequired(props) {
    const auth = useAuth();
    const loc = useLocation();

    if (auth.user !== null) {
        return (<> {props.children} </>)
    }
    else {
        return <Navigate to={"/login"} state={{from: loc}}/>
    }

}

export default AuthRequired;