Make sure user is available (ie. backend api not down)
This commit is contained in:
parent
2c43076497
commit
c22a3048dc
2 changed files with 5 additions and 2 deletions
|
@ -526,7 +526,7 @@ export function doSignIn() {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const user = selectUser(state);
|
const user = selectUser(state);
|
||||||
|
|
||||||
if (pushNotifications.supported) {
|
if (pushNotifications.supported && user) {
|
||||||
pushNotifications.reconnect(user.id);
|
pushNotifications.reconnect(user.id);
|
||||||
pushNotifications.validate(user.id);
|
pushNotifications.validate(user.id);
|
||||||
}
|
}
|
||||||
|
@ -545,7 +545,7 @@ export function doSignOut() {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const user = selectUser(state);
|
const user = selectUser(state);
|
||||||
try {
|
try {
|
||||||
if (pushNotifications.supported) {
|
if (pushNotifications.supported && user) {
|
||||||
await pushNotifications.disconnect(user.id);
|
await pushNotifications.disconnect(user.id);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -19,6 +19,7 @@ export default () => {
|
||||||
const [user] = useState(selectUser(store.getState()));
|
const [user] = useState(selectUser(store.getState()));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!user) return;
|
||||||
setPushSupported(pushNotifications.supported);
|
setPushSupported(pushNotifications.supported);
|
||||||
if (pushNotifications.supported) {
|
if (pushNotifications.supported) {
|
||||||
pushNotifications.subscribed(user.id).then((isSubscribed: boolean) => {
|
pushNotifications.subscribed(user.id).then((isSubscribed: boolean) => {
|
||||||
|
@ -31,6 +32,7 @@ export default () => {
|
||||||
useMemo(() => setPushEnabled(pushPermission === 'granted' && subscribed), [pushPermission, subscribed]);
|
useMemo(() => setPushEnabled(pushPermission === 'granted' && subscribed), [pushPermission, subscribed]);
|
||||||
|
|
||||||
const subscribe = async () => {
|
const subscribe = async () => {
|
||||||
|
if (!user) return;
|
||||||
setEncounteredError(false);
|
setEncounteredError(false);
|
||||||
try {
|
try {
|
||||||
if (await pushNotifications.subscribe(user.id)) {
|
if (await pushNotifications.subscribe(user.id)) {
|
||||||
|
@ -49,6 +51,7 @@ export default () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const unsubscribe = async () => {
|
const unsubscribe = async () => {
|
||||||
|
if (!user) return;
|
||||||
if (await pushNotifications.unsubscribe(user.id)) {
|
if (await pushNotifications.unsubscribe(user.id)) {
|
||||||
setSubscribed(false);
|
setSubscribed(false);
|
||||||
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'unsubscribed' });
|
analytics.reportEvent('browser_notification', { [GA_DIMENSIONS.ACTION]: 'unsubscribed' });
|
||||||
|
|
Loading…
Reference in a new issue