Development and Production Projects with Firebase

Hey everyone!

Currently I am working on an app that is currently in beta. I added firebase analytics in this app, but I am also still doing development. This causes my analytics to be polluted with my own data from development. Because of this, I created a new firebase project to use when developing. However, every time I want to build my app or publish it (for OTA updates), I have to swap out the firebase credentials in my app.json. Is there a way to automatically swap between two versions of credentials when creating a production build? The only thing I can think of is creating my own script to do this, but I was wondering if there may be a built in way with expo to do this?

This is basically the same thing as the following issue by orteidni, which was recently closed. Multiple Firebase projects within a single Expo managed application

Any sort of help or guidance would be super helpful! Thanks in advance! :blush:

1 Like

@orteidni I decided to create a custom CLI within my project to solve this issue. Now I am able to run a single command to swap my credentials in the app.json file. This CLI also changes a global constant variable in the expo project. This allows me to have different behavior within the application if you are in dev vs production mode (don’t necessarily need different behavior between the modes, but it allows for it if needed).

Here is a link to my implementation if this helps anyone: salad-bowl-app/nyx at master · asoomar/salad-bowl-app · GitHub
Here is also a link to the initial issue I created within my project that outlines the problem: [1.2] Create CLI for switching between prod and dev · Issue #34 · asoomar/salad-bowl-app · GitHub

The CLI I created is called Nyx and its fairly straightforward to use. If anyone uses this, I just want to clarify that this does not work for all configs in app.json. For my problem, I just needed to swap the iOS GoogleService-Info.plist and firebase configs in app.json, so that’s exactly what this does. You can look at the code to see how your project should be structured in order for this CLI to work. Additionally, if you want to add more credentials that need to be swapped, it should be pretty easy to do so (add more filenames to necessaryFiles in constants,js, add onto the switchMode function in parser.js).

1 Like

Great stuff! But after publishing the app it’s not possible to change the credentials “on-the-run” via Javascript? The CLI streamlines the process of putting settings and credentials to the correct setup before publishing to a preferred channel for instance?

Yes thats exactly right. Shifting between development and production before a release won’t do anything unless you publish (so you definitely need to be cautious about ensuring you’re on production mode before publishing via OTA). However, I can imagine something like this being fairly easy to implement through the CLI as well. You can have an extra layer of protection if you made a feature to publish through this command which could automatically ensure that you are in the right mode.

What I made was to just streamline the process of switching between the modes. I can imagine this being annoying or tedious to do if you’re constantly publishing or making new builds.

hi @asoomar is this approach that you asking? having flavor on our expo app? so every app-{env}.json have their own firebase credential