PrivateRoute.js 952 Bytes
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
2
3
4
import { Redirect, Route } from "react-router-dom";
// import { useAuth } from "../context/auth_context";
import ErrorPage from "../pages/ErrorPage";

Kim, Subin's avatar
Kim, Subin committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const PrivateRoute = ({ component: Component, ...rest }) => {
    //   const { user } = useAuth();
    //   return (
    //     <Route
    //       {...rest}
    //       render={(props) => {
    //         if (user) {
    //           if (rest.role) {
    //             if (rest.role === user.role) {
    //               return <Component {...props} />;
    //             } else {
    //               return <ErrorPage />
    //             }
    //           } else {
    //             return <Component {...props} />
    //           }
    //         } else {
    //           return <Redirect to="/login" />;
    //         }
    //       }}
    //     />
    //   );
    return (
        <Route {...rest} render={(props) => <Component {...props} />} />
    )
Kim, Subin's avatar
Kim, Subin committed
30
31
32
};

export default PrivateRoute;