@kadconsulting/dry
Version:
KAD Reusable Component Library
21 lines • 945 B
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
// TODO-p2: Update React Router Dom Navigation to Include next/navigation or make an HOC to do so as well
import { Navigate } from 'react-router-dom';
export const ProtectedRoute = ({ children }) => {
const [isLoggedIn, setIsLoggedIn] = useState(null);
useEffect(() => {
const checkLoggedIn = async () => {
// TODO-p2: fix implementation to be way more dynamic
};
checkLoggedIn();
}, []);
if (isLoggedIn === null) {
return null; // Show a loading spinner or something similar here
}
return isLoggedIn ? _jsx(_Fragment, { children: children }) : _jsx(Navigate, { to: '/' });
};
export const withProtectedRoute = (Component, props) => {
return (_jsx(ProtectedRoute, { children: _jsx(Component, { ...props }) }));
};
//# sourceMappingURL=ProtectedRoute.js.map