redux-auth-saga

0.2.0 • Public • Published

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

Dependencies (3)

Dev Dependencies (12)

Package Sidebar

Install

npm i redux-auth-saga

Weekly Downloads

0

Version

0.2.0

License

ISC

Last publish

Collaborators

  • kjaenicke