Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Created August 24, 2018 14:38
Show Gist options
  • Save brunokrebs/c5b52035964c4a24858812b5c41fce5d to your computer and use it in GitHub Desktop.
Save brunokrebs/c5b52035964c4a24858812b5c41fce5d to your computer and use it in GitHub Desktop.
React component to secure another component.
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