AdminRoute.js 408 Bytes
Newer Older
kusang96's avatar
kusang96 committed
1
2
3
4
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { isAdmin } from '../utils/auth';

kusang96's avatar
kusang96 committed
5
function PrivateRoute({ path, children }) {
kusang96's avatar
kusang96 committed
6
7
8
9
10
11
12
  if (isAdmin()) {
    return (
      <Route path={path}>
        {children}
      </Route>
    )
  } else {
kusang96's avatar
DSAD    
kusang96 committed
13
    alert('권한이 없습니다. 죄송합니다.');
kusang96's avatar
kusang96 committed
14
15
16
17
18
19
20
    return (
      <Redirect to='/' />
    )
  }
}

export default PrivateRoute