1

I am using react node js with SQL. When I logout from reactJS I am removing the token while logging out. But still when i login within different credentials it takes me to dashboard with old user data and when I refresh page i get the data with new currently logged in user.

What could be it The code part is pretty much correct I guess because it shows perfect data after page refresh.

my logout action

export const logoutAction = () => {
    return dispatch => {
        localStorage.removeItem('tkn')
        dispatch({ type: LOGOUT, payload: "" })
    }
}

logout reducer

case LOGOUT:
        return {
            ...state,
            token: action.payload,
            isAuth: false,
        }

Triggered action from the navbar

  const logout = () => {
    props.logoutUser()
    handleDrawerClose()
  }
Sagar Chavan
  • 249
  • 5
  • 14

1 Answers1

0

I Had the same problem. My APP get a JWT auth token from a ASP.NET Web API and use this for display some items after login. But when the user loggout and other user does login, the data from the first user apear instead off the last user data. I found a session cookie and I resolved the problem installing the react-native-cookies package (@react-native-cookies/cookies). https://github.com/react-native-cookies/cookies

yarn add @react-native-cookies/cookies

After this, on my AuthActions, on my Logout routine, I call clearAll() method.

import CookieManager from '@react-native-cookies/cookies';

export const userLogout = () => {
  CookieManager.clearAll();

  return (dispatch) => {
    dispatch({type: LOGOUT_ACTION});
    // more actions...
  };
};
regisls
  • 529
  • 6
  • 23