From 99c6ea30a926fe16cb7b6d857521ce0f66a25693 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 16 Dec 2021 09:04:15 -0800 Subject: [PATCH] Resolve unsub issue. --- .../profile-shops/profile-shops.container.jsx | 16 +++++++++++----- client/src/redux/user/user.sagas.js | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/client/src/components/profile-shops/profile-shops.container.jsx b/client/src/components/profile-shops/profile-shops.container.jsx index ecfc6a03a..4b3eaafe1 100644 --- a/client/src/components/profile-shops/profile-shops.container.jsx +++ b/client/src/components/profile-shops/profile-shops.container.jsx @@ -35,11 +35,17 @@ export function ProfileShopsContainer({ bodyshop }) { const updateActiveShop = async (activeShopId) => { logImEXEvent("profile_change_active_shop"); - await axios.post("/notifications/unsubscribe", { - fcm_tokens: await getToken(messaging), - imexshopid: bodyshop.imexshopid, - type: "messaging", - }); + try { + const fcm_tokens = await getToken(messaging); + + await axios.post("/notifications/unsubscribe", { + fcm_tokens, + imexshopid: bodyshop.imexshopid, + type: "messaging", + }); + } catch (error) { + console.log("No FCM token. Skipping unsubscribe."); + } await Promise.all( data.associations.map(async (record) => { await updateAssocation({ diff --git a/client/src/redux/user/user.sagas.js b/client/src/redux/user/user.sagas.js index 0507d109b..46d07443f 100644 --- a/client/src/redux/user/user.sagas.js +++ b/client/src/redux/user/user.sagas.js @@ -101,13 +101,19 @@ export function* signOutStart() { logImEXEvent("redux_sign_out"); const state = yield select(); - console.log(yield getToken(messaging)); + //unsub from topic. - yield call(axios.post, "/notifications/unsubscribe", { - fcm_tokens: yield getToken(messaging), - imexshopid: state.user.bodyshop.imexshopid, - type: "messaging", - }); + + try { + const fcm_tokens = yield getToken(messaging); + yield call(axios.post, "/notifications/unsubscribe", { + fcm_tokens, + imexshopid: state.user.bodyshop.imexshopid, + type: "messaging", + }); + } catch (error) { + console.log("No FCM token. Skipping unsubscribe."); + } yield signOut(auth); yield put(signOutSuccess());