Skip to content

Redux middleware for Oauth2 connection on the client side. Tokens are stored via cookie.

Notifications You must be signed in to change notification settings

mikespencer/auth-fe-middleware

Repository files navigation

Build Status Coverage Status js-standard-style Code Climate

meetup-auth-fe-middleware

Redux middleware for Oauth2 connection on the client side. Tokens are stored in localStorage.

Installation

npm install --save meetup-auth-fe-middleware

Usage

import { applyMiddleware } from 'redux'
import authMiddleware from 'meetup-auth-fe-middleware'

applyMiddleware(
    authMiddleware({
      clientId: 'your-client-id', // required
      redirectUri: 'your-redirect-uri', //required
      authUrl: 'https://secure.dev.meetup.com/oauth2/authorize/' // required
    })
  )

Connecting

  1. dispatch this action:
import { INIT_AUTH } from 'meetup-auth-fe-middleware'

{
  type: INIT_AUTH
}

Getting the token

  1. dispatch this action:
import { CONFIGURE } from 'meetup-auth-fe-middleware'

{
  type: CONFIGURE
}
  1. This will call the next reducer with either:
{
  type: TOKEN_RETRIEVED,
  payload: {
    token // the retrieved token
  }
}

or:

{
  type: TOKEN_NOT_FOUND
}
  1. in your reducer:
import { TOKEN_RETRIEVED } from 'meetup-auth-fe-middleware'

// ...
case TOKEN_RETRIEVED:
  return { token: action.payload.token } // state === { token }
// ...

Disconnect

  1. Dispatch this action:
import { REMOVE_TOKEN } from 'meetup-auth-fe-middleware'

{
  type: REMOVE_TOKEN
}
  1. in your reducer:
import { REMOVE_TOKEN } from 'meetup-auth-fe-middleware'

// ...
case REMOVE_TOKEN:
  return { token: null } // state === { token: null }
// ...

Updating this package

  1. Make your changes
  2. npm version major|minor|patch. This will:
  3. Run unit tests
  4. Run eslint
  5. Update the version number in package.json
  6. Commit the update and also create a corresponding git tags
  7. Push the update and tag to GitHub
  8. npm publish to push the update to NPM

About

Redux middleware for Oauth2 connection on the client side. Tokens are stored via cookie.

Resources

Stars

Watchers

Forks

Packages

No packages published