fix race condition which logged out users

This commit is contained in:
martin-mfg
2026-01-04 22:50:33 +01:00
parent addc4391fd
commit 150a433a3d
3 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ function App() {
if (userKey && userKey.length > 0) {
const userAccess = await getUserMetadata(userKey);
if (userAccess === null) {
dispatch(_logout());
dispatch(_logout(userKey));
} else {
setUserAccess(userAccess);
}
@@ -6,8 +6,8 @@ export function login(userId, userKey) {
return { type: LOGIN, payload: { userId, userKey } };
}
export function logout() {
return { type: LOGOUT, payload: {} };
export function logout(userKey = null) {
return { type: LOGOUT, payload: { userKey: userKey } };
}
export function setUserAccess(token, privateAccess) {
@@ -19,6 +19,12 @@ export default (state = initialState, action) => {
userKey: action.payload.userKey,
};
case types.LOGOUT:
if (
action.payload.userKey === null ||
action.payload.userKey !== localStorage.getItem('userKey')
) {
return;
}
localStorage.clear();
return {
userId: null,