Make sure user is available (ie. backend api not down)

This commit is contained in:
Dan Peterson 2021-12-29 13:03:05 -06:00 committed by Thomas Zarebczan
parent 2c43076497
commit c22a3048dc
2 changed files with 5 additions and 2 deletions

View file

@ -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 {

View file

@ -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' });