@conduction/components
Version:
React (Gatsby) components used within the Conduction Skeleton Application (and its implementations)
16 lines (15 loc) • 598 B
JavaScript
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { navigate } from "gatsby";
export const PrivateRoute = ({ children, authenticated }) => {
const [_authenticated, setAuthenticated] = React.useState(false);
React.useEffect(() => {
if (!authenticated && window.location.pathname !== "/login") {
navigate("/login");
}
authenticated && setAuthenticated(true);
}, [authenticated]);
if (!_authenticated)
return _jsx(_Fragment, {});
return _jsx(_Fragment, { children: children });
};