Handle invalid sessionUser. Don't store invalid sessionUser.

This commit is contained in:
Alex Gleason 2021-04-10 17:15:52 -05:00
parent 0b87296c15
commit 070a7d410d
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -16,7 +16,16 @@ const defaultState = ImmutableMap({
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')));
// 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 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 => {
persistAuth(state);