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 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 {
|
||||
|
|
|
@ -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' });
|
||||
|
|
Loading…
Reference in a new issue