From 070a7d410d0a4d62a2dc039808a9c2ce17c1b524 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 10 Apr 2021 17:15:52 -0500 Subject: [PATCH] Handle invalid sessionUser. Don't store invalid sessionUser. --- app/soapbox/reducers/auth.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/soapbox/reducers/auth.js b/app/soapbox/reducers/auth.js index 5be27ac1a..29953f0b3 100644 --- a/app/soapbox/reducers/auth.js +++ b/app/soapbox/reducers/auth.js @@ -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);