mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-02 18:20:06 +00:00
24 lines
632 B
TypeScript
24 lines
632 B
TypeScript
import React, { ReactElement, useContext, FunctionComponent } from "react";
|
|
import { Redirect, Route } from "react-router-dom";
|
|
import { AppContext } from "@sasjs/test-framework";
|
|
|
|
interface PrivateRouteProps {
|
|
component: FunctionComponent;
|
|
exact?: boolean;
|
|
path: string;
|
|
}
|
|
|
|
const PrivateRoute = (
|
|
props: PrivateRouteProps
|
|
): ReactElement<PrivateRouteProps> => {
|
|
const { component, path, exact } = props;
|
|
const appContext = useContext(AppContext);
|
|
return appContext.isLoggedIn ? (
|
|
<Route component={component} path={path} exact={exact} />
|
|
) : (
|
|
<Redirect to="/login" />
|
|
);
|
|
};
|
|
|
|
export default PrivateRoute;
|