React-boilerplate: logout action not working on browser refresh

Created on 1 Mar 2017  路  3Comments  路  Source: react-boilerplate/react-boilerplate

logout is working If I didn't refresh the browser.After refeshing the browser logout not working. Is there any solution for it?
Below is the saga code that I had written for the logout action

//...function

    export function* logout() {
          yield put({ type: 'SENDING_REQUEST', sending: true });

          try {
            let response = yield call(auth.logout);
            yield put({ type: 'SENDING_REQUEST', sending: false });
          } catch (error) {
            yield put({ type: 'REQUEST_ERROR', error: error.message });
          }
        }

        export function* logoutFlow() {
          while (true) {
            yield take('LOGOUT');
            yield put({ type: 'SET_AUTH', newAuthState: false });
            yield call(logout);
            forwardTo('/login');
          }
        }

        export function* logoutRoot() {
          yield fork(logoutFlow);
        }

        export function* watcherRoot() {
          const watcher2 = yield fork(logoutRoot);
        }

        export default [
          mainRoot,
          watcherRoot,
        ];

Most helpful comment

code is correct and working fine now.
Problem is with global saga. saga should be in app level(global) to work. Earlier injected auth saga in component level thats why it didn't work after browser refresh

All 3 comments

Hello @prudhvisays, what is auth.logout doing ? Is it possible that you actually are setting the authstate to false on logout, but some 'autologin' is happening (on reload) because of the fact that localstorage is checked for some data (maybe a token ?) when the store is initiated - which happens on reload ?

code is correct and working fine now.
Problem is with global saga. saga should be in app level(global) to work. Earlier injected auth saga in component level thats why it didn't work after browser refresh

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bsr203 picture bsr203  路  4Comments

loicginoux picture loicginoux  路  4Comments

mxstbr picture mxstbr  路  3Comments

hieubq90 picture hieubq90  路  3Comments

VadimuZz picture VadimuZz  路  4Comments