Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including redux-auth-saga with all npm packages installed. Try it out:

var reduxAuthSaga = require("redux-auth-saga")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

redux-auth-saga v0.2.0

Authorization Saga designed for Redux

redux-auth-saga build:


Redux saga designed to handle a simple token-based authentication flow. This package was inspired by this thread by Yassine Elouafi

Installation

$ npm install --save redux-auth-saga

Building

$ npm run build

Example usage

Attaching redux-auth-saga to your root saga

import 'redux-auth-saga' from 'redux-auth-saga'

const options = {
    storageType: 'sessionStorage',
    loginActionType: 'USER_LOGIN',
    logoutActionType: 'USER_LOGOUT',
    onLoginAction: userLogin,
    onLogoutAction: userLogout,
    endpoint: 'http://localhost/auth',
    redirectToOnLogout: () => {}
}

export default function* rootSaga() {
    yield [
        fork(reduxAuthSaga, options),
        fork(anotherSaga),
        ...
    ];
}

Available Options

| Name | Type | Required | Description | |---|---|---|---|---| | storageType | String ('sessionStorage or localStorage') (default: 'sessionStorage') | No | What type of storage to use for token | | loginActionType | String | Yes | String constant to take for login dispatch | | logoutActionType | String | Yes | String constant to take for logout dispatch | | onLoginAction | Function | Yes | Action to dispatch when login is successful | | onLogoutAction | Function | Yes | Action to dispatch when logout is successful | | endpoint | String | Yes | Authentication endpoint | | redirectToOnLogout | Function | Yes | Used to redirect to after logout |

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free