Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sonjoydatta/react-access-boundary

Repository files navigation

react-access-boundary

A simple component to check the user has permission to access wrapped UI components or not.

version MIT License

Quick Start

  1. Installation: It should be installed on your react project dependencies by running either of the following:
yarn add react-access-boundary
# or
npm i react-access-boundary
  1. Usage: First, you need to wrap the application or private layouts with <AccessProvider> then you are ready to use this <AccessBoundary>
const App = () => {
 const permissions = ['MY_ACCOUNT', 'ORDER_VIEW', 'ORDER_EDIT', 'ORDER_UPDATE', 'ORDER_DELETE'];
 return (
 <AccessProvider permissions={permissions}>
 <YourApplicationRoutes />
 </AccessProvider>
 );
};

Protect page

const CustomerOrders = () => {
 return (
 <AccessBoundary to="ORDER_VIEW" isDefaultFallback>
 // Your Customer Order component
 </AccessBoundary>
 );
};
export default CustomerOrders;

Protect UI component

<AccessBoundary to="ORDER_DELETE">
 <button class="ActionButton">Delete Order</button>
</AccessBoundary>

Conditional render with useContext

const { isAllowedTo } = useAccessContext();
<button class="ActionButton">{isAllowedTo('ORDER_UPDATE') ? 'Update Order' : 'Preview Order'}</button>;

Can I contribute?

Sure, open an issue, point out errors, and what not. Wanna fix something yourselves, you're welcome to open a PR and I appreciate it.

License

MIT

About

πŸ” A library for validating user permissions from UI layers and will show default unauthorised fallback if needed.

Topics

Resources

License

Stars

Watchers

Forks

Packages

Contributors

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /