Created
August 10, 2019 10:35
-
-
Save acomito/495ccaf506d187c800c975f02477f587 to your computer and use it in GitHub Desktop.
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
// TOP LEVEL IMPORTS | |
import React from 'react'; | |
import { Route, Redirect } from 'react-router-dom'; | |
class ProtectedRoute extends React.Component { | |
render() { | |
const { | |
currentUser, | |
path, | |
noNav, | |
noFooter, | |
theme, | |
location, | |
isAllowed, | |
component: Component, | |
layout: Layout, | |
...rest | |
} = this.props; | |
if ( | |
currentUser && | |
currentUser.roles && | |
currentUser.roles.includes('appAdmin') | |
) { | |
return <Redirect to="/admin" />; | |
} | |
return ( | |
<Route | |
{...rest} | |
path={path} | |
render={args => ( | |
<div style={{ height: '100%' }}> | |
{currentUser && currentUser.id ? ( | |
<Layout {...args} {...this.props}> | |
<Component {...args} {...this.props} /> | |
</Layout> | |
) : ( | |
<Redirect to="/login" /> | |
)} | |
</div> | |
)} | |
/> | |
); | |
} | |
} | |
export default ProtectedRoute; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment