Skip to content

Instantly share code, notes, and snippets.

@antyakushev
Created November 7, 2016 12:13
Show Gist options
  • Save antyakushev/9c6d51f1353b81d595bee2e5422191b7 to your computer and use it in GitHub Desktop.
Save antyakushev/9c6d51f1353b81d595bee2e5422191b7 to your computer and use it in GitHub Desktop.
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),
]
}
@kwanzu
Copy link

kwanzu commented Dec 14, 2019

nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment