Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function* signInSuccess(request) {
- const token = request.data.auth_mobile;
- yield put(signInSuccessAction({ token }));
- yield fork(loadProfile, token);
- }
- function* signInFailed(request) {
- yield put(signInErrorAction({ errorResponse: request.data.message }));
- }
- function* signIn(phone, password) {
- const { globalPhone, localPhone } = phoneUtils(phone);
- try {
- const request = yield call(signInRequest, {
- login: localPhone[0],
- phone: globalPhone,
- password,
- });
- if (request.success) {
- yield call(signInSuccess, request);
- } else {
- yield call(signInFailed, request);
- }
- } catch (error) {
- yield console.log(error);
- } finally {
- if (yield cancalled()) {
- yield put(signInCancalledAction());
- }
- }
- }
- function* signOut() {
- yield console.log('SIGN_OUT');
- }
- function* authFlowWatcher() {
- while (true) {
- const { payload } = yield take(authTypes.SIGN_IN_REQUEST);
- yield fork(signIn, payload.phone, payload.password);
- yield take(authTypes.SIGN_OUT_REQUEST);
- yield fork(signOut);
- }
- }
- export default authFlowWatcher;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement