Firebase Admin SDK: Resolve Deployment Environment Issues

https://www.ionos.com/digitalguide/fileadmin/DigitalGuide/Teaser/error-t.jpg

Have you ever wonder once you had a working application running in your local machine, but once deployed it in a server or cloud, all of a sudden it starts not to work because of a Firebase issue.

Then, here are some tips that could help you to narrow down and hopefully fix the issue.

If you see any error like below, then this article will help to narrow down and fix the issue

The log says the below message

There are two likely causes: (1) your server time is not properly synced or (2) your certificate key file has been revoked. To solve (1), re-sync the time on your server. To solve (2), make sure the key ID for your key file is still present at https://console.firebase.google.com/iam-dmin/serviceaccounts/project . If not, generate a new key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk

But if this issue is only in a new/single environment, then we can simply neglect the second solution. Because we can assume that the key is present and valid.

The following are the first suggestions to solve the issue.

Check the server time

The most common issue would be that the server’s clock is not properly synced. Since the firebase applications generate an auth token with google servers, token validation requires a proper synced clock. So the first step is to check the time of the server.

Assuming the server is running on Linux, you can use the date command.

$ date -u

The issue is not related to the timezone. Firebase Admin SDK will work on any timezone. But if you check the UTC time, it should be the same everywhere since use the same time zone.

Fix the time issue

You can adjust your clock using the NTP. Based on your server version you can set up a time synchronization service appropriately.

Check the Environment Variables

If you are providing some credentials using environment variables to the Firebase Admin SDK, then you will have to recheck the values in the deployed environment as well. Because a single invalid character is more than enough to fail the SDK initialization.

  • If your deployments are on Kubernetes or Openshift environment, then will have to check the associated config maps and secrets

If nothing will resolve the issue, we will have to proceed with a remote debugging.

But before move into that step, you may check just execute a Firebase SDK only code snippet (just the admin SDK initialization) will be helpful. Until that simple code is not running properly will have to continue the environment adjustments.

Further Documentation

Senior Software Engineer