Skip to content

Instantly share code, notes, and snippets.

@zulucoda
Last active January 27, 2019 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zulucoda/c6a18e10f6c5e441137493769aad73ab to your computer and use it in GitHub Desktop.
Save zulucoda/c6a18e10f6c5e441137493769aad73ab to your computer and use it in GitHub Desktop.
Before Refactor - user login proccess
/**
* Before Refactor - user login proccess
* @see https://blog.mfbproject.co.za
*/
export function* userLoginSaga() {
// 1. get the username and password from state.
const { username, password } = yield select(getLoginFormState);
// 2. call login API endpoint with the username and password
const loginService = new LoginService();
const loginResponse = yield call([loginService, get, username, password]);
// 3. set auth token in store
yield put(LoginActions.setAuthToken(loginResponse.token));
//4. remove the username and password from store
yield put(LoginActions.clearLogin());
//5. call settings API endpoint with authorisation token
const settingsService = new SettingsService();
const setingsResponse = yield call([settingsService, get]);
//6. set the user settings in store
yield put(SettingsActions.onReceiveSettings(setingsResponse));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment