From 8f338a8d882cb7bc927674e65e6ed6ab18299446 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sun, 28 Aug 2022 22:40:57 -0700 Subject: [PATCH] Prevent embeds from breaking in Chrome incognito (#814) --- web/components/auth-context.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/components/auth-context.tsx b/web/components/auth-context.tsx index ea01ce1e..7347d039 100644 --- a/web/components/auth-context.tsx +++ b/web/components/auth-context.tsx @@ -19,6 +19,15 @@ import { useStateCheckEquality } from 'web/hooks/use-state-check-equality' type AuthUser = undefined | null | UserAndPrivateUser 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 = () => { let deviceToken = localStorage.getItem('device-token')