From 3a0da484552f84403a5f5c0e302768ed648282b7 Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 26 Mar 2020 13:56:00 +0100 Subject: [PATCH] =?UTF-8?q?AuthorizedRoute=20avec=20v=C3=A9rification=20ro?= =?UTF-8?q?les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/app.js | 4 +++- frontend/src/components/AuthorizedRoute.js | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/frontend/src/app.js b/frontend/src/app.js index 56df924..3849d53 100644 --- a/frontend/src/app.js +++ b/frontend/src/app.js @@ -23,7 +23,9 @@ export class App extends Component { - + } /> diff --git a/frontend/src/components/AuthorizedRoute.js b/frontend/src/components/AuthorizedRoute.js index 9d7c6f5..31014a1 100644 --- a/frontend/src/components/AuthorizedRoute.js +++ b/frontend/src/components/AuthorizedRoute.js @@ -1,7 +1,23 @@ import { Route } from 'react-router'; +import PropTypes from 'prop-types'; + +export function AuthorizedRoute({ required, roles, ...props}) { + if ( !roles.includes(required) ) { + return ( +
+
+ Vous ne pouvez pas accéder à cette page. +
+
+ ); + } -export function AuthorizedRoute({...props}) { return ( - ) + ); } + +AuthorizedRoute.propTypes = { + required: PropTypes.string.isRequired, + roles: PropTypes.arrayOf(PropTypes.string).isRequired +};