From c22a3048dc9595c512c3e0afde6ac2ed33ddd65b Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Wed, 29 Dec 2021 13:03:05 -0600 Subject: [PATCH] Make sure user is available (ie. backend api not down) --- ui/redux/actions/app.js | 4 ++-- .../browserNotificationSettings/use-browser-notifications.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index 5d90e22b1..bcc4068f8 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -526,7 +526,7 @@ export function doSignIn() { const state = getState(); const user = selectUser(state); - if (pushNotifications.supported) { + if (pushNotifications.supported && user) { pushNotifications.reconnect(user.id); pushNotifications.validate(user.id); } @@ -545,7 +545,7 @@ export function doSignOut() { const state = getState(); const user = selectUser(state); try { - if (pushNotifications.supported) { + if (pushNotifications.supported && user) { await pushNotifications.disconnect(user.id); } } finally { diff --git a/web/component/browserNotificationSettings/use-browser-notifications.js b/web/component/browserNotificationSettings/use-browser-notifications.js index ca06111fb..be42eaa57 100644 --- a/web/component/browserNotificationSettings/use-browser-notifications.js +++ b/web/component/browserNotificationSettings/use-browser-notifications.js @@ -19,6 +19,7 @@ export default () => { const [user] = useState(selectUser(store.getState())); useEffect(() => { + if (!user) return; setPushSupported(pushNotifications.supported); if (pushNotifications.supported) { pushNotifications.subscribed(user.id).then((isSubscribed: boolean) => { @@ -31,6 +32,7 @@ export default () => { useMemo(() => setPushEnabled(pushPermission === 'granted' && subscribed), [pushPermission, subscribed]); const subscribe = async () => { + if (!user) return; setEncounteredError(false); try { if (await pushNotifications.subscribe(user.id)) { @@ -49,6 +51,7 @@ export default () => { }; const unsubscribe = async () => { + if (!user) return; if (await pushNotifications.unsubscribe(user.id)) { setSubscribed(false); analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'unsubscribed' });