How to handle multiple firebase projects server side?
Each FirebaseApp
instance must be given a unique name. You can look up instances by their names. See the examples in the documentation: https://firebase.google.com/docs/admin/setup#initialize_multiple_apps
Robert Benedetto
Updated on December 12, 2022Comments
-
Robert Benedetto over 1 year
I have SaaS application that needs 4 mobile apps (built in Flutter):
- iOS/Android version of a customer app
- iOS/Android version of admin app
Initially, I was thinking of having a single Firebase project where all 4 apps reside, but I have read that this may not be the best way to handle things (Firebase FCM, multiple apps in the same firebase project).
I have no issues breaking it up to two Firebase projects, one for the customer app and one for the admin app, but how do I then handle this server side when my API is to send pushes?
Server is using .Net, and right now I am using Global.asmx to create the firebase instance:
protected void Application_Start(object sender, EventArgs e) { // Enable firebase FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/customerapp-245105.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging") }); }
But this will only enable the customer app? How do I also create the admin app?
Im assuming that I can't simply do:
protected void Application_Start(object sender, EventArgs e) { // Enable firebase FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/customerapp-245105.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging") }); FirebaseApp.Create(new AppOptions() { Credential = GoogleCredential.FromFile(HostingEnvironment.MapPath(@"~/App_Data/adminapp-244405.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging") }); }
And, how do I tell the instances apart when calling them in the webservice? As the first instance would be used when sending pushes to customers, and the second for admin?
-
Robert Benedetto over 4 yearsYeah, turns out it was as easy as that. Just add the instance name as a parameter when calling .Create(), then get the instance using FirebaseApp.GetInstance("<instance name>");