Redux saga designed to handle a simple token-based authentication flow. This package was inspired by this thread by Yassine Elouafi
$ npm install --save redux-auth-saga
$ npm run build
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),
...
];
}
| 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 |