From a971a0a363ddb065b99d6f3f029ba654283798a4 Mon Sep 17 00:00:00 2001 From: sdimitris Date: Mon, 3 Jan 2022 13:02:19 +0200 Subject: [PATCH] fix(pushNotifications): Prevent firebase app from initializing more than one time --- .../push-notifications/src/providers/Firebase.provider.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/push-notifications/src/providers/Firebase.provider.ts b/modules/push-notifications/src/providers/Firebase.provider.ts index 6773a9bd9..bdaca90f0 100644 --- a/modules/push-notifications/src/providers/Firebase.provider.ts +++ b/modules/push-notifications/src/providers/Firebase.provider.ts @@ -20,8 +20,12 @@ export class FirebaseProvider implements IPushNotificationsProvider { const firebaseOptions: firebase.AppOptions = { credential: firebase.credential.cert(serviceAccount), }; + try { + this.fcm = firebase.app(serviceAccount.projectId).messaging(); + } catch (e) { + this.fcm = firebase.initializeApp(firebaseOptions, serviceAccount.projectId).messaging(); + } - this.fcm = firebase.initializeApp(firebaseOptions).messaging(); } // TODO check for disabled notifications for users