Advertisement
Dodo67

AdminRoute.jsx

Feb 7th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { Route, Navigate } from 'react-router-dom';
  3. import { isAuth } from '../helpers/auth';
  4.  
  5. const AdminRoute = ({ component: Component, ...rest }) => (
  6.     <Route
  7.         {...rest}
  8.         render={props =>
  9.             isAuth() && isAuth().role === 'admin' ? (
  10.                 <Component {...props} />
  11.             ) : (
  12.                 <Navigate
  13.                     to={{
  14.                         pathname: '/signin',
  15.                         state: { from: props.location }
  16.                     }}
  17.                 />
  18.             )
  19.         }
  20.     ></Route>
  21. );
  22.  
  23. export default AdminRoute;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement