Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created November 4, 2018 16:07
Show Gist options
  • Save amandeepmittal/e8f59e108a303a1bb8c373fce2dbbdcb to your computer and use it in GitHub Desktop.
Save amandeepmittal/e8f59e108a303a1bb8c373fce2dbbdcb to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { Route, Redirect } from 'react-router-dom';
import auth from './auth-helper';
const PrivateRoute = ({ component: Component, ...rest }) => (
<Route
{...rest}
render={props =>
auth.isAuthenticated() ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: '/signin',
state: { from: props.location }
}}
/>
)
}
/>
);
export default PrivateRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment