meetup-auth-fe-middleware
v0.1.6
Published
Redux middleware for Oauth2 connection on the client side. Tokens are stored via cookie.
Downloads
3
Readme
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
- dispatch this action:
import { INIT_AUTH } from 'meetup-auth-fe-middleware'
{
type: INIT_AUTH
}
Getting the token
- dispatch this action:
import { CONFIGURE } from 'meetup-auth-fe-middleware'
{
type: CONFIGURE
}
- This will call the next reducer with either:
{
type: TOKEN_RETRIEVED,
payload: {
token // the retrieved token
}
}
or:
{
type: TOKEN_NOT_FOUND
}
- in your reducer:
import { TOKEN_RETRIEVED } from 'meetup-auth-fe-middleware'
// ...
case TOKEN_RETRIEVED:
return { token: action.payload.token } // state === { token }
// ...
Disconnect
- Dispatch this action:
import { REMOVE_TOKEN } from 'meetup-auth-fe-middleware'
{
type: REMOVE_TOKEN
}
- in your reducer:
import { REMOVE_TOKEN } from 'meetup-auth-fe-middleware'
// ...
case REMOVE_TOKEN:
return { token: null } // state === { token: null }
// ...
Updating this package
- Make your changes
npm version major|minor|patch
. This will:- Run unit tests
- Run eslint
- Update the version number in
package.json
- Commit the update and also create a corresponding git tags
- Push the update and tag to GitHub
npm publish
to push the update to NPM