Reputation: 1980
I have a thunk action that logout the user
inside the logout thunk action I have this: dispatch(push('/login'));
I would like to redirect the user with a "refresh" to logout in order to refresh the page and. "clean' the state
also, I would like to clean the redux store, and not its not clean
import { push } from 'connected-react-router';
export function logout() {
return async (dispatch: any, state: State, services: Services) => {
try {
await services.auth.logout();
} catch (e) {
services.logger.error(e);
} finally {
dispatch({ type: AUTH_LOGOUT });
dispatch(push('/login'));
}
};
}
also when click on a button from component I have
const Logout = () => {
const dispatch = useDispatch();
React.useEffect(() => {
dispatch(logout());
}, [dispatch]);
return null;
};
Reducer
case AUTH_LOGOUT: {
draft.authenticated = false;
draft.currentUser = {} ;
return draft;
}
Upvotes: 0
Views: 3502
Reputation: 667
You could use javascript's window object for refresh.
e.g., window.location.href = "router_address"
Upvotes: 0
Reputation: 162
React automatically reloads when you change a state. So you need to change a state. For example a login/logout flag or an authorization flag you have used. From Your code, you need to change it where you have defined your case for AUTH_LOGOUT in your reducer.
Upvotes: 0