Created
August 24, 2018 14:38
-
-
Save brunokrebs/c5b52035964c4a24858812b5c41fce5d to your computer and use it in GitHub Desktop.
React component to secure another component.
This file contains hidden or 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 from 'react'; | |
import {Route} from 'react-router-dom'; | |
import auth0Client from '../Auth'; | |
function SecuredRoute({ component: Component, ...rest }) { | |
return ( | |
<Route {...rest} render={(props) => { | |
if (!auth0Client.isAuthenticated()) return auth0Client.signIn(); | |
return <Component {...props} /> | |
}} /> | |
); | |
} | |
export default SecuredRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment