From 1ef1af8234b5e701e52b3c8f1472b297977bd0df Mon Sep 17 00:00:00 2001 From: James Grugett Date: Wed, 5 Oct 2022 16:49:28 -0500 Subject: [PATCH] Fix localstorage saved user being overwritten on every page load --- web/components/auth-context.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/components/auth-context.tsx b/web/components/auth-context.tsx index 19ced0b2..223fe123 100644 --- a/web/components/auth-context.tsx +++ b/web/components/auth-context.tsx @@ -68,11 +68,11 @@ export function AuthProvider(props: { }, [setAuthUser, serverUser]) useEffect(() => { - if (authUser != null) { + if (authUser) { // Persist to local storage, to reduce login blink next time. // Note: Cap on localStorage size is ~5mb localStorage.setItem(CACHED_USER_KEY, JSON.stringify(authUser)) - } else { + } else if (authUser === null) { localStorage.removeItem(CACHED_USER_KEY) } }, [authUser])