Handle invalid sessionUser. Don't store invalid sessionUser.

bundle-emoji
Alex Gleason 2021-04-10 17:15:52 -05:00
rodzic 0b87296c15
commit 070a7d410d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 17 dodań i 2 usunięć

Wyświetl plik

@ -16,7 +16,16 @@ const defaultState = ImmutableMap({
me: null, me: null,
}); });
const sessionUser = sessionStorage.getItem('soapbox:auth:me'); const getSessionUser = () => {
const id = sessionStorage.getItem('soapbox:auth:me');
if (id && typeof id === 'string' && id !== 'null' && id !== 'undefined') {
return id;
} else {
return undefined;
}
};
const sessionUser = getSessionUser();
const localState = fromJS(JSON.parse(localStorage.getItem('soapbox:auth'))); const localState = fromJS(JSON.parse(localStorage.getItem('soapbox:auth')));
// If `me` doesn't match an existing user, attempt to shift it. // If `me` doesn't match an existing user, attempt to shift it.
@ -55,7 +64,13 @@ const migrateLegacy = state => {
}; };
const persistAuth = state => localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS())); const persistAuth = state => localStorage.setItem('soapbox:auth', JSON.stringify(state.toJS()));
const persistSession = state => sessionStorage.setItem('soapbox:auth:me', state.get('me'));
const persistSession = state => {
const me = state.get('me');
if (me && typeof me === 'string') {
sessionStorage.setItem('soapbox:auth:me', me);
}
};
const persistState = state => { const persistState = state => {
persistAuth(state); persistAuth(state);