I'm trying to clear "roles" since I'm fetching from my backend to authorize the flow to certain routes based on the role.
When the user clicks "log out," I'm running the following code:
const invalidateCredentials = () => {
queryClient.removeQueries();
queryClient.clear();
userTokenStore.setState({ role: '', isLoggedIn: false, token: '', storeId: '' })
localStorage.removeItem("user-auth");
return <Navigate to="/login" replace />;
};
The problem is that if I try to log in with a user with a different role, the same role remains. But if I log out, reload, and log in with the other user, it works.
How can I make this work?