Fix localstorage saved user being overwritten on every page load
This commit is contained in:
parent
189da4a0cf
commit
1ef1af8234
|
@ -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])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user