Fix localstorage saved user being overwritten on every page load

This commit is contained in:
James Grugett 2022-10-05 16:49:28 -05:00
parent 189da4a0cf
commit 1ef1af8234

View File

@ -68,11 +68,11 @@ export function AuthProvider(props: {
}, [setAuthUser, serverUser]) }, [setAuthUser, serverUser])
useEffect(() => { useEffect(() => {
if (authUser != null) { if (authUser) {
// Persist to local storage, to reduce login blink next time. // Persist to local storage, to reduce login blink next time.
// Note: Cap on localStorage size is ~5mb // Note: Cap on localStorage size is ~5mb
localStorage.setItem(CACHED_USER_KEY, JSON.stringify(authUser)) localStorage.setItem(CACHED_USER_KEY, JSON.stringify(authUser))
} else { } else if (authUser === null) {
localStorage.removeItem(CACHED_USER_KEY) localStorage.removeItem(CACHED_USER_KEY)
} }
}, [authUser]) }, [authUser])