0.1.1 • Published 6 years ago

@kreativwebdesign/react-authorizer v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

💂‍♂️ react-authorizer 💂‍♀️

Basic library for handling authorization in your React app.

WIP

This module is not finished yet, so it's not using semantic versioning Things to watch out for:

  • Better documentation
  • More examples

    Out of Scope

  • Authentication

Usage

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>

API

AuthProvider

Props

Nametyperequireddefault value
rolesArrayYes-

Authorize

Props

Nametyperequireddefault value
neededRolesArrayYes-
childrenfunction({ isAuthorized: Boolean, missingRoles: Array, lacksRole: (role: String) => Boolean, hasRole: (role: String) => Boolean}) => propTypes.nodeYes-

Examples

See some examples in action on codesandbox here.

Development

You must use yarn to maintain the project.

Install

run yarn install

Test

run yarn run test

Build

run yarn run build

Publishing

Attention! Use with care.

run yarn run release