Skip to content

moser-inc/redux-auth-saga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 |

About

Authorization Saga designed for Redux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published