8000 GitHub - Blevs/react-permissions: React Permissions - Conditional permissions rendering modeled after React Router
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Blevs/react-permissions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Permissions

<PermissionsSwitch>
  <Can permissions="user:read">
    <button>
      Load history
    </button>
  </Can>
  <Can permissions={["user:write", "user:admin"]}>
    <button>
      Modify history
    </button>
  </Can>
</PermissionsSwitch>

Have you ever needed users to see different things based on their role or permissions? Have you ever marveled at the magic that is react-router?

Look no further, as we create permission based routing inspired by React Router!

Also we are doing this in TypeScript. For those of you who are new to TypeScript, this will be a gentle, and shallow introduction. You will be able to follow along and simply ignore the small amounts of TypeScript if you wish.

Goals

  • [ ] Create a context provider to hold current user permissions (ex. Router)
  • [ ] Create a hook to use our context (ex. useLocation)
  • [ ] Create a component (Can) that conditionally renders its children based on permissions given as props (ex. Route)
  • [ ] Create a component that renders the first matching Can (ex. Switch)
  • [ ] Learn enough TypeScript to be dangerous

Stretch Goals

  • [ ] Write a PrivateRoute component that combines permissions with routing
  • [ ] Integrate with an actual authentication system, like Auth0, Firebase, or Okta.
  • [ ] Write a Switch capable of checking both the route and permissions match.
  • [ ] Extend Can to work with roles, authenticated states, or whatever else your application needs

About

React Permissions - Conditional permissions rendering modeled after React Router

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0