nahuelbkn

PrivateRoute.js

Jan 13th, 2021
729
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import  React from  "react";
  2. import { Route, Redirect } from  "react-router-dom";
  3. import { getSessionToken } from '../../helpers/sessionStorage';
  4.  
  5. const  PrivateRoute = ({ component, path, exact }) => {
  6.  
  7.     const token = getSessionToken();
  8.  
  9.     return  token ? (
  10.         <Route  path={path}  exact={exact} component={component} />
  11.     ) : ( <Redirect  to="/login"  /> );
  12. };
  13.  
  14.  
  15. export  default  PrivateRoute;
RAW Paste Data