11// @flow
22import { put , call , take , select , all , takeLatest } from 'redux-saga/effects' ;
33import { delay as delayPromise } from 'redux-saga' ;
4+ import { push } from 'react-router-redux' ;
45import { fromJS } from 'immutable' ;
56
67import {
@@ -49,6 +50,9 @@ export const logUserOut = () => action(AUTH.logout);
4950
5051export const tokenSelector = ( state : RootStateType ) => state . auth . get ( 'token' ) ;
5152
53+ export const locationSelector = ( state : RootStateType ) =>
54+ state . routing . location ;
55+
5256export const changesetIdSelector = ( state : RootStateType ) =>
5357 state . changeset . get ( 'changesetId' ) ;
5458
@@ -121,7 +125,9 @@ export function* watchAuth(): any {
121125
122126 yield take ( AUTH . logout ) ;
123127 delayBy = DELAY ;
124- yield call ( logoutFlow , delayBy ) ;
128+ token = undefined ;
129+ yield call ( logoutFlow ) ;
130+ yield call ( delay , delayBy ) ;
125131 } catch ( error ) {
126132 console . log ( error ) ;
127133 yield put ( action ( AUTH . loginError , error ) ) ;
@@ -133,12 +139,16 @@ export function* watchAuth(): any {
133139 kind : 'warning'
134140 } )
135141 ) ;
142+ yield take ( AUTH . logout ) ;
136143 delayBy = 4 * delayBy ;
144+ token = undefined ;
145+ yield call ( logoutFlow ) ;
146+ yield call ( delay , delayBy ) ;
137147 }
138148 }
139149}
140150
141- export function * logoutFlow ( { delayBy } : { delayBy : int } ) : any {
151+ export function * logoutFlow ( ) : any {
142152 yield call ( removeItem , 'token' ) ;
143153 yield call ( removeItem , 'oauth_token' ) ;
144154 yield call ( removeItem , 'oauth_token_secret' ) ;
@@ -150,7 +160,13 @@ export function* logoutFlow({ delayBy }: { delayBy: int }): any {
150160 yield put ( action ( CHANGESETS_PAGE . fetch , { pageIndex } ) ) ;
151161 }
152162 yield put ( action ( AUTH . clearUserDetails ) ) ;
153- yield call ( delay , delayBy ) ;
163+ let location = yield select ( locationSelector ) ;
164+ yield put (
165+ push ( {
166+ ...location ,
167+ pathname : '/'
168+ } )
169+ ) ;
154170}
155171
156172export function * authTokenFlow ( ) : any {
0 commit comments