ppob-frontend/src/component/PrivateRoute.js
2021-12-09 09:01:39 +07:00

19 lines
566 B
JavaScript

import React from 'react';
import {Redirect, Route} from 'react-router-dom';
import {useStore} from "../utils/useStore";
// import { isLogin } from '../utils';
export const PrivateRoute = ({component: Component, ...rest}) => {
const store = useStore();
return (
// Show the component only when the user is logged in
// Otherwise, redirect the user to /signin page
<Route {...rest} render={props => (
store.authentication.isLoggedIn ?
<Component {...props} />
: <Redirect to="/login"/>
)}/>
);
};