skip to Main Content

We have implemented the notifications and it works fine when we do the regular testing. However, when concurrent users uses the same API then we get below error.

The default firebaseapp already exists. However, by checking the solution on the internet, we have implemented the below solution in the class constructor

if (FirebaseApp.DefaultInstance == null)
{
    FirebaseApp.Create(new AppOptions()
    {
        Credential = GoogleCredential.FromJson(JsonConvert.SerializeObject(<Passing Firebase Config here>))
    });
}

Then sending the notification using this code:

string result = await FirebaseMessaging.DefaultInstance.SendAsync(message);

Still we are getting the error as default FirebaseApp already exists.

Any help on this is appreciated!

2

Answers


  1. Please provide more context:

    1. include the surrounding method for both snippets.
    2. When you say "in the class constructor" what class are you referring to? How is it used?
    Login or Signup to reply.
  2. import firebase_admin
    from firebase_admin import credentials, firestore

    class FirebaseManager:
    def init(self):
    if not firebase_admin._apps:
    cred = credentials.Certificate(‘path/to/your/serviceAccountKey.json’)
    firebase_admin.initialize_app(cred, {
    ‘databaseURL’: ‘https://your-database-url.firebaseio.com’
    })
    self.db = firestore.client()

    Usage

    firebase_manager = FirebaseManager()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search