Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. function* signInSuccess(request) {
  2. const token = request.data.auth_mobile;
  3. yield put(signInSuccessAction({ token }));
  4. yield fork(loadProfile, token);
  5. }
  6.  
  7. function* signInFailed(request) {
  8. yield put(signInErrorAction({ errorResponse: request.data.message }));
  9. }
  10.  
  11. function* signIn(phone, password) {
  12. const { globalPhone, localPhone } = phoneUtils(phone);
  13. try {
  14. const request = yield call(signInRequest, {
  15. login: localPhone[0],
  16. phone: globalPhone,
  17. password,
  18. });
  19.  
  20. if (request.success) {
  21. yield call(signInSuccess, request);
  22. } else {
  23. yield call(signInFailed, request);
  24. }
  25. } catch (error) {
  26. yield console.log(error);
  27. } finally {
  28. if (yield cancalled()) {
  29. yield put(signInCancalledAction());
  30. }
  31. }
  32. }
  33.  
  34. function* signOut() {
  35. yield console.log('SIGN_OUT');
  36. }
  37.  
  38. function* authFlowWatcher() {
  39. while (true) {
  40. const { payload } = yield take(authTypes.SIGN_IN_REQUEST);
  41.  
  42. yield fork(signIn, payload.phone, payload.password);
  43.  
  44. yield take(authTypes.SIGN_OUT_REQUEST);
  45.  
  46. yield fork(signOut);
  47. }
  48. }
  49.  
  50. export default authFlowWatcher;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement