mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
24 lines
621 B
TypeScript
24 lines
621 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
|