npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@byu-law/feathers-reduxify-authentication

v1.1.0

Published

Wrap feathers-client.authentication so it works with Redux, as well as authentication, authorization packages for React-Router.

Downloads

2

Readme

Forked Changes:

Forked from https://github.com/eddyystop/feathers-reduxify-authentication

  1. Changed the user payload to reflect the options passed for initialization. For example:
    const feathersAuthentication = reduxifyAuthentication(feathersClient, {
       user: 'member' // Changing the 'user' option to me 'member'
    });
    Now the state will hold the payload for the 'member' object instead of 'user.'

feathers-reduxify-authentication

Wrap feathers-client.authentication so it works transparently with Redux, as well as authentication, authorization packages for React-Router.

Build Status

  • Work with standard feathers-client.authentication on the client.
  • Dispatch feathers authentication and logout to Redux.
  • Integrate with react-router and react-router-redux.
  • Use popular Redux, React-Router authentication and authorization packages for React routing.

Code Examples

What we want to be able to do

This is typical code for React routing and permissions.

import { UserAuthWrapper } from 'redux-auth-wrapper';

// Define permissions
const UserIsAuthenticated = UserAuthWrapper({
  authSelector: (state) => state.auth.user, // BEING ABLE TO DO THIS IS ONE REASON TO USE THIS REPO
  predicate: user => user && user.isVerified,
  ...
});
const UserIsAdmin = UserAuthWrapper({
  authSelector: (state) => state.auth.user, // BEING ABLE TO DO THIS IS ONE REASON TO USE THIS REPO
  predicate: user => user && user.isVerified && user.roles && user.roles.indexOf('admin') !== -1,
  ...
});

// React routing
<Provider store={store}>
  <Router history={history}>
    <Route path="/" component={AppWrapper}>
      <Route path="/user/profilechange"
        component={UserIsAuthenticated(UserProfileChange)} // USER MUST BE AUTHENTICATED
      />
      <Route path="/user/roleschange"
        component={UserIsAuthenticated(UserIsAdmin(UserRolesChange))} // AUTHENTICATED AND ADMIN
      />
    </Route>
  </Router>
</Provider>

require('feathers-client').authentication cannot be used as-is in this scenario or other scenarios involving Redux-based projects.

feathers-reduxify-authentication wraps feathers-client.authentication so it behaves transparently as 100% compatible Redux code.

Making feathers-client.authentication work with Redux

You wrap require('feathers-client').authentication, insert the wrapper's reducer into Redux's combineReducers, and use the wrapper's action creators with Redux's dispatch.

Voila, 100% Redux compatible with the current user retained in Redux's store.

import feathers from 'feathers-client';
import feathersReduxifyAuthentication from 'feathers-reduxify-authentication';

// Configure feathers-client
const app = feathers(). ... .configure(feathers.authentication({ ... });

// Reduxify feathers-client.authentication
feathersAuthentication = reduxifyAuthentication(app,
  { isUserAuthorized: (user) => user.isVerified } // WE INSIST USER IS 'verified' TO AUTHENTICATE
);

// Add to Redux reducer
const rootReducer = combineReducers({ ..., auth: feathersAuthentication.reducer, ...});

// Dispatch actions as needed. Params are the same as for feathers.authentication().
dispatch(feathersAuthentication.authenticate({ type: 'local', email, password })).then().catch();
dispatch(feathersAuthentication.logout());

Working Example

This package is used in feathers-starter-react-redux-login-roles which implements full featured local authentication with user roles, email verification, forgotten passwords, etc.

You can review how that project uses feathers-reduxify-authentication:

  • client/feathers/index.js configures feathers and reduxifies feathers-client.authentication.
  • client/reducers/index.js adds our authentication to Redux's reducers. Our current user will be stored at state.auth.user.
  • client/index.js sets up React routing and permissions.
  • client/screens/Users/UserSignIn/FormContainer.js both authenticates users and logs them out.

Motivation

  • Feathers is a great real-time client-server framework.
  • Redux is a great state container for the front-end.
  • React is a great declarative UI.
  • React-Router is a complete routing library for React by React.
  • There are several packages which handle authentication and authorization for React-Router and Redux.

This repo let's everyone work together easily.

Installation

Install Nodejs.

Run npm install --save-dev feathers-reduxify-authentication in your project folder.

You can then:

// ES6
import feathersReduxifyAuthentication from 'feathers-reduxify-authentication';
// ES5
const feathersReduxifyAuthentication = require('feathers-reduxify-authentication');

/src on GitHub contains the ES6 source.

API Reference

Each module is fully documented.

Also see Working example above.

Build

npm test to transpile the ES6 code in /src to ES5 in /lib.

Contributing

Contribute to this repo.

Guide to ideomatic contributing.

Change Log

List of notable changes.

License

MIT. See LICENSE.