Created
April 23, 2017 17:10
-
-
Save Metnew/a447a53d4ed4e04d47ea5e1563828e8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react' | |
import PropTypes from 'prop-types' | |
import {Route, Redirect} from 'react-router' | |
/** | |
* Component that protects route from unauthorized users. | |
* @type {Object} | |
*/ | |
class RouteAuth extends Component { | |
static propTypes = { | |
canAccess: PropTypes.func, | |
component: PropTypes.func, | |
path: PropTypes.string, | |
exact: PropTypes.bool, | |
strict: PropTypes.bool | |
} | |
render () { | |
let {canAccess, component, path, exact, strict} = this.props | |
let routeProps = { | |
path, | |
component, | |
exact, | |
strict | |
} | |
return canAccess(path) ? <Route {...routeProps} /> : <Redirect to="/auth" /> | |
} | |
} | |
export default RouteAuth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment