Basic library for handling authorization in your React app.
This module is not finished yet, so it's not using semantic versioning Things to watch out for:
- Better documentation
- More examples
- Authentication
Wrap your React tree inside the AuthProvider Component and pass the roles of the active user as an Array.
<AuthProvider roles={[ 'user', 'admin' ]}>
{/* your react tree */}
</AuthProvider>
And then somewhere inside this tree:
<Authorize neededRoles={[ 'user', 'admin' ]}>
{
({ isAuthorized, missingRoles, lacksRole }) => {
if (isAuthorized) {
return 'Welcome buddy';
} else if (lacksRole('admin')) {
return 'Sorry you are not an admin';
} else {
return 'You are not authorized too see anything here'
}
}
}
</Authorize>
Name | type | required | default value |
---|---|---|---|
roles | Array | Yes | - |
Name | type | required | default value |
---|---|---|---|
neededRoles | Array | Yes | - |
children | function({ |
Yes | - |
See some examples in action on codesandbox here.
You must use yarn
to maintain the project.
run yarn install
run yarn run test
run yarn run build
Attention! Use with care.
run yarn run release