Created
April 3, 2017 09:00
-
-
Save GiladShoham/f9176ccc9d4385499ed1568feef18d41 to your computer and use it in GitHub Desktop.
React Authorizaion component
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
import {AdminOnly, ManagerOnly} from 'Authorization'; | |
export default ( | |
<div> | |
<Route path="/" component={Base}> | |
{ /* A route only admin can visit */ } | |
<Route path="admin" component={AdminOnly(AdminDashboard, {redirectTo: '/home'})}/> | |
{ /* A route only manager (and admins) can visit */ } | |
<Route path="manager" component={ManagerOnly(ManagerDashboard, {redirectTo: '/home'})}/> | |
</Route> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Someone came up with almost the exact solution you did 2 years ago... https://hackernoon.com/role-based-authorization-in-react-c70bb7641db4 but not as complete.