Skip to content

Instantly share code, notes, and snippets.

@acomito
Created August 10, 2019 10:35
Show Gist options
  • Save acomito/495ccaf506d187c800c975f02477f587 to your computer and use it in GitHub Desktop.
Save acomito/495ccaf506d187c800c975f02477f587 to your computer and use it in GitHub Desktop.
// 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