react-auth-wrapper
v1.0.0
Published
A utility library for handling authentication and authorization for react apps
Downloads
591
Readme
React Auth Wrapper
Decouple your Authentication and Authorization from your components!
react-auth-wrapper
is a utility library for handling authentication and authorization in react + react-router applications.
Note: This is a fork of a prior work that was directly coupled to Redux. See the original work by Matt Russell to compare.
Installation
npm install --save react-auth-wrapper
Usage
This package exports four different higher-order components that you can use to wrap any component that needs to verify authentication status prior to rendering in your app.
- withAuth - checks for
isAuthenticated
andisAuthenticating
props to show or hide your component - withAuthFromContext - Like
withAuth
except you also provide your Context Consumer that holds your auth info (and any optional selector/prop-name ifisAuthenticated
andisAuthenticating
are not inside your Context provider's state) - withAuthAndRedirect - Like
withAuth
except will also allow redirecting to a given URL/route when un-authenticated and return to your component once authenticated - withAuthFromContextAndRedirect - Like
withAuthFromContext
except will also allow redirecting to a given URL/route when un-authenticated and return to your component once authenticated
Docs
View the full docs. These are always in-sync with the JsDoc code annotations.