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

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

export default PrivateRoute;