authoc
v0.0.4
Published
Higher order component for React Redux Router authentication and redirection
Downloads
10
Readme
authoc is a Private Route solution for React apps that use React-Redux, and React Router.
Installation
npm install --save authoc
This module is only for projects that use React, Redux, React-Redux, and React-Router (4+)
Usage:
In your React Router config, simply pass the protected component(React Component), redirect route (String), and the auth field target in Redux state (Array).
import authoc from 'authoc';
import { Route } from 'react-router-dom';
import Protected from './components/Protected';
/*
example_Redux_State = {
auth: {
authenticated: false // any non-truthy value undefined, false, null ...
},
{...otherKeys}
};
// the target is state.auth.authenticated
*/
const protectedComponent = authoc(Protected, '/', ['auth', 'authenticated']);
<Route path="/secretpage" component={protectedComponent} />
TODO:
- Write tests
- Publish babel transpiled version
- Provide an option to pass a mock object rather than an array of keys for state target