EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 445 forks source link

Multi Firebase Environments #1727

Closed pandabuilt closed 3 years ago

pandabuilt commented 3 years ago

If we have separate firebase projects, how do we connect to each one individually?

Is this as easy as get the secret from an endpoint in the parent project and reinitialize with those secrets?

anarnoli commented 3 years ago

Hey @pandabuilt - is this you got resolved? I'm struggling to setup it.

pandabuilt commented 3 years ago

Okay this is complicated.

I have multiple app resources. Then I use nativescript hooks to pull in which resources to use. Then you have to update the nativescript.json file to have the right bundle id.

Step 1 - create a folder with your app resources per environment

Step 2 - pass in a flag in ns debug to determine which env to use.

Step 3 - in before prepare hook check that flag and use getNativeScriptCongig($injector) and setValue of the appResourcesPath to the right environment.

Note: injector gets passed in hooks.

anarnoli commented 3 years ago

Hi @pandabuilt,

I have observed @nativescript/firebase is doing the job and it creates GooglService-Info.plist based on passed param like --env.dev or --env.prod

Now the next problem is: I wanted to set REVERSED_CLIENT_ID in build.xcconfig file by reading GooglService-Info.plist so that it can be read by Info.plist.

However if I hardcode REVERSED_CLIENT_ID = something then in Info.plist I am able to read this variable as ${REVERSED_CLIENT_ID}

pandabuilt commented 3 years ago

How I solved this:

Since google-info.plist does all the magic you can create multiple App_Resources folders.

Then from there you can use an environment like --env.production = true. Then inside your webpack.config file you can do some logic for fileReplacement to use the right file!