0.2.0 • Published 7 years ago

redux-auth-saga v0.2.0

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

redux-auth-saga


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

NameTypeRequiredDescription
storageTypeString ('sessionStorage or localStorage') (default: 'sessionStorage')NoWhat type of storage to use for token
loginActionTypeStringYesString constant to take for login dispatch
logoutActionTypeStringYesString constant to take for logout dispatch
onLoginActionFunctionYesAction to dispatch when login is successful
onLogoutActionFunctionYesAction to dispatch when logout is successful
endpointStringYesAuthentication endpoint
redirectToOnLogoutFunctionYesUsed to redirect to after logout
0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago