Created
November 7, 2016 12:13
-
-
Save antyakushev/9c6d51f1353b81d595bee2e5422191b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bindWatcher, redirect } from './utils' | |
import { fork, take, call, put } from 'redux-saga/effects' | |
import { replaceStateByPath } from 'reduceless' | |
import { reset } from 'redux-form' | |
import * as calls from 'services/user' | |
import * as acts from 'actions/user' | |
const { login, logout, forgot, resetPass, user } = acts | |
export const watchUserLogout = bindWatcher(logout, calls.logoutUser) | |
export const watchForgotPassword = bindWatcher(forgot, calls.forgot) | |
export const watchResetPassword = bindWatcher(resetPass, calls.reset) | |
export const watchCurrentUser = bindWatcher( | |
user, | |
calls.fetchCurrentUser, | |
[login.reqs.success], | |
) | |
export function* onLogin() { | |
while (true) { | |
yield take(login.reqs.success.getType()) | |
yield put(replaceStateByPath('auth', { loggedIn: true })) | |
yield put(reset('login-form')) | |
redirect('/overview') | |
} | |
} | |
export function* onLogout() { | |
while (true) { | |
yield take(logout.init.getType()) | |
yield put(replaceStateByPath('auth', { loggedIn: false })) | |
yield call(calls.logoutUser) | |
redirect('/login') | |
} | |
} | |
export function* watchLogin() { | |
yield [ | |
fork(bindWatcher(login, calls.loginUser)), | |
fork(onLogin), | |
fork(onLogout), | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice work