fix race condition which logged out users
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user