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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@apim/auth0-lock-redux

v1.0.2

Published

Auth Lock Redux Middleware

Downloads

15

Readme

auth0-lock-redux

npm GitHub issues GitHub license

Auth Lock Redux Middleware

This middleware facilitates Auth0 Lock & Redux integration.

Installation

npm install --save @apim/auth0-lock-redux

Features

  • Use your own action to trigger authentication by passing the right meta information.
  • Right after authentication, the user's profile is fetched automatically and made available for reduction. Use the bundled reducer to grab the full profile or write your own.
  • Auth0 Lock first gives us an authentication payload (with the token and auth-only data) and then gives us profile data (via another call). This middleware returns both in one object by moving the auth object to be under profile.auth
  • All Auth0 Lock events are mapped to actions. Only "authenticated" is really being used but I am planning to add more.
  • Nicely formatted for redux-logger.
  • I intentionally leave out any routing changes and localStorage. Use your own middleware to do either. Yes, I consider this a feature.

Usage

Middleware Setup

import auth0LockReduxMiddleware from '@apim/auth0-lock-redux'

// Auth0 Lock key (see auth0-lock docs)
const options = {
  key: '...',
  domain: '...',
  options: {}
}

// Add it to your middleware array
const middlewares = [
  auth0LockReduxMiddleware(options)
]

// Apply as usual
applyMiddleware(...middlewares)

Alternatively, if you already have an instance of auth0-lock with your settings, pass the instance and it'll be used instead:

import Auth0Lock from 'auth0-lock'
import auth0LockReduxMiddleware from '@apim/auth0-lock-redux'

const auth0lock = new Auth0Lock(/* key */, /* domain */, /* options */)

// Add it to your middleware array
const middlewares = [
  auth0LockReduxMiddleware(auth0lock)
]

// Apply as usual
applyMiddleware(...middlewares)

Triggering Authentication

For now, the way to trigger authentication if you don't do it directly with your own instance of auth0-lock is to set the meta value for your action of choice to the value of the AUTHENTICATE constant.

import { AUTHENTICATE } from '@apim/auth0-lock-redux'

const SIGN_IN = () => ({
  type: 'SIGN_IN',
  meta: AUTHENTICATE // Internally it looks like this: '@@auth0Lock/AUTHENTICATE'
})

Reducer (optional)

Add a reducer to reduce the received user profile. You have two options:

Use the bundled reducer and get the full object:

import { AUTHENTICATED, auth0LockReducer } from '@apim/auth0-lock-redux'
const reducers = combineReducers({
  user: auth0LockReducer
})

Add your own reducer to the PROFILE action:

This lets you customize the reduction. I'm using redux-actions in this example.

import {
  AUTHENTICATED,
  REVOKED,
  PROFILE,
  auth0LockReducer
} from '@apim/auth0-lock-redux'

const user = handleActions({
  [REVOKED]: () => null,
  [PROFILE]: (state, action) => ({
    ...state,
    token: action.payload.auth.accessToken, // Grab only the token
    name: action.payload.name // ...and the user's name
  })
}, state.user)

Reduce noise in redux-logger

Add a reducer to reduce the received user profile. You have two options:

// Collapse these entries...
createLogger({
  collapsed: (getState, action) => /auth0Lock/.test(action.type)
});

// Or omit it completely...
createLogger({
  predicate: (getState, action) => !/router/.test(action.type)
});

Constants

// [TODO] Some initialization may be added in the future.
const INITIALIZE = '@@auth0Lock/INITIALIZE'
// Trigger authentication.
const AUTHENTICATE = '@@auth0Lock/AUTHENTICATE'
// When profile is received.
const PROFILE = '@@auth0Lock/PROFILE'
// When profile load fails.
const PROFILE_ERROR = '@@auth0Lock/PROFILE_ERROR'
// [TODO] Dispatched when token revoked (aka: sign out)
const REVOKED = '@@auth0Lock/REVOKED'
// [TODO] Dispatched when token is checked.
const CHECK = '@@auth0Lock/CHECK'
// Dispatched when sign in form is shown.*
const SHOW = '@@auth0Lock/SHOW'
// Dispatched when sign in form is hidden.*
const HIDE = '@@auth0Lock/HIDE'
// Dispatched when lock emits an unrecoverable_error.*
const UNRECOVERABLE_ERROR = '@@auth0Lock/UNRECOVERABLE_ERROR'
// Dispatched when token is received.*
const AUTHENTICATED = '@@auth0Lock/AUTHENTICATED'
// Dispatched when authentication fails.*
const AUTHORIZATION_ERROR = '@@auth0Lock/AUTHORIZATION_ERROR'
// Dispatched when a hash parse attempt is done.*
const HASH_PARSED = '@@auth0Lock/HASH_PARSED'
  • Note: these are straight maddings of Auth0 Lock's own events. See their docs.