Prevent embeds from breaking in Chrome incognito
This commit is contained in:
parent
6c64c9f1cd
commit
180ed0d74f
|
@ -19,6 +19,15 @@ import { useStateCheckEquality } from 'web/hooks/use-state-check-equality'
|
||||||
type AuthUser = undefined | null | UserAndPrivateUser
|
type AuthUser = undefined | null | UserAndPrivateUser
|
||||||
|
|
||||||
const CACHED_USER_KEY = 'CACHED_USER_KEY_V2'
|
const CACHED_USER_KEY = 'CACHED_USER_KEY_V2'
|
||||||
|
// Proxy localStorage in case it's not available (eg in incognito iframe)
|
||||||
|
const localStorage =
|
||||||
|
typeof window !== 'undefined'
|
||||||
|
? window.localStorage
|
||||||
|
: {
|
||||||
|
getItem: () => null,
|
||||||
|
setItem: () => {},
|
||||||
|
removeItem: () => {},
|
||||||
|
}
|
||||||
|
|
||||||
const ensureDeviceToken = () => {
|
const ensureDeviceToken = () => {
|
||||||
let deviceToken = localStorage.getItem('device-token')
|
let deviceToken = localStorage.getItem('device-token')
|
||||||
|
@ -59,7 +68,7 @@ export function AuthProvider(props: {
|
||||||
current = (await createUser({ deviceToken })) as UserAndPrivateUser
|
current = (await createUser({ deviceToken })) as UserAndPrivateUser
|
||||||
}
|
}
|
||||||
setAuthUser(current)
|
setAuthUser(current)
|
||||||
// Persist to local storage, to reduce login blink next time.
|
// Persist to localStorage, 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(current))
|
localStorage.setItem(CACHED_USER_KEY, JSON.stringify(current))
|
||||||
setCachedReferralInfoForUser(current.user)
|
setCachedReferralInfoForUser(current.user)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user