PrivateRoute.js 419 Bytes
Newer Older
Lee SeoYeon's avatar
.    
Lee SeoYeon committed
1
2
3
import React from 'react'
import { Route, Redirect } from 'react-router-dom'
import { isAuthenticated } from "../utils/auth";
Lee SeoYeon's avatar
..    
Lee SeoYeon committed
4

Lee SeoYeon's avatar
.    
Lee SeoYeon committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function PrivateRoute({path, children}) {
    if (isAuthenticated()) {
        return (
            <Route path={path}>
                {children}
            </Route>
        )
    } else {
        return (
            <Redirect to='/login' />
        )
    }
}

export default PrivateRoute