AuthorizedRoute avec vérification roles
This commit is contained in:
parent
29e112ae7d
commit
3a0da48455
@ -23,7 +23,9 @@ export class App extends Component {
|
|||||||
<Route path='/logout' exact component={LogoutPage} />
|
<Route path='/logout' exact component={LogoutPage} />
|
||||||
<Route path='/home' exact component={LazyHomePage} />
|
<Route path='/home' exact component={LazyHomePage} />
|
||||||
<Route path='/dashboard-client' exact component={DashBoardClient} />
|
<Route path='/dashboard-client' exact component={DashBoardClient} />
|
||||||
<AuthorizedRoute path='/dashboard-dev' exact component={DashBoardDev} />
|
<AuthorizedRoute
|
||||||
|
roles={['ROLE_USER']} required='ROLE_DEV'
|
||||||
|
path='/dashboard-dev' exact component={DashBoardDev} />
|
||||||
<Route component={() => <Redirect to="/home" />} />
|
<Route component={() => <Redirect to="/home" />} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
|
@ -1,7 +1,23 @@
|
|||||||
import { Route } from 'react-router';
|
import { Route } from 'react-router';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
export function AuthorizedRoute({ required, roles, ...props}) {
|
||||||
|
if ( !roles.includes(required) ) {
|
||||||
|
return (
|
||||||
|
<div className="message is-danger">
|
||||||
|
<div className="message-body">
|
||||||
|
Vous ne pouvez pas accéder à cette page.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function AuthorizedRoute({...props}) {
|
|
||||||
return (
|
return (
|
||||||
<Route {...props} />
|
<Route {...props} />
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuthorizedRoute.propTypes = {
|
||||||
|
required: PropTypes.string.isRequired,
|
||||||
|
roles: PropTypes.arrayOf(PropTypes.string).isRequired
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user