Remove console.log. Log onIdTokenChanged error.

This commit is contained in:
James Grugett 2022-08-29 00:26:12 -05:00
parent 71dfcc4dd9
commit ecacce0796

View File

@ -46,30 +46,35 @@ export function AuthProvider(props: {
}, [setAuthUser, serverUser]) }, [setAuthUser, serverUser])
useEffect(() => { useEffect(() => {
return onIdTokenChanged(auth, async (fbUser) => { return onIdTokenChanged(
console.log('onIdTokenChanged', fbUser) auth,
if (fbUser) { async (fbUser) => {
setTokenCookies({ if (fbUser) {
id: await fbUser.getIdToken(), setTokenCookies({
refresh: fbUser.refreshToken, id: await fbUser.getIdToken(),
}) refresh: fbUser.refreshToken,
let current = await getUserAndPrivateUser(fbUser.uid) })
if (!current.user || !current.privateUser) { let current = await getUserAndPrivateUser(fbUser.uid)
const deviceToken = ensureDeviceToken() if (!current.user || !current.privateUser) {
current = (await createUser({ deviceToken })) as UserAndPrivateUser const deviceToken = ensureDeviceToken()
current = (await createUser({ deviceToken })) as UserAndPrivateUser
}
setAuthUser(current)
// Persist to local storage, to reduce login blink next time.
// Note: Cap on localStorage size is ~5mb
localStorage.setItem(CACHED_USER_KEY, JSON.stringify(current))
setCachedReferralInfoForUser(current.user)
} else {
// User logged out; reset to null
deleteTokenCookies()
setAuthUser(null)
localStorage.removeItem(CACHED_USER_KEY)
} }
setAuthUser(current) },
// Persist to local storage, to reduce login blink next time. (e) => {
// Note: Cap on localStorage size is ~5mb console.error(e)
localStorage.setItem(CACHED_USER_KEY, JSON.stringify(current))
setCachedReferralInfoForUser(current.user)
} else {
// User logged out; reset to null
deleteTokenCookies()
setAuthUser(null)
localStorage.removeItem(CACHED_USER_KEY)
} }
}) )
}, [setAuthUser]) }, [setAuthUser])
const uid = authUser?.user.id const uid = authUser?.user.id