how to add firebase service account key on railway and handle in python code

suraj-bhatt1217
HOBBY

5 days ago

how to add firebase service account key on railway and handle in python code

$10 Bounty

1 Replies

Step 1

  • In the Firebase console, navigate to your project's settings by clicking the gear icon next to "Project Overview."

  • Select Project settings, then go to the Service accounts tab

  • Click the Generate new private key button. A confirmation pop-up will appear

  • Click Generate Key to download a JSON file containing your service account credentials

  • Store this JSON file securely and do not commit it to a public code repository, as it provides administrative access to your Firebase project

Step 2

  • Open your project in the Railway dashboard and navigate to the service where you want to add the key, the one hosting the python code.

  • Go to the Variables tab.

  • Click on New Variable. It is recommended to add the key via the Raw Editor to ensure correct formatting.

  • Create a variable named FIREBASE_CREDENTIALS_JSON.

  • Open the JSON file you downloaded from Firebase, copy its entire content, and paste it as the value for the FIREBASE_CREDENTIALS_JSON variable

Step 3

Use it! You might need to adjust the dependencies you import according to your use case

import os
import json

# Retrieve the JSON credentials from the environment variable
firebase_creds_json_str = os.environ.get('FIREBASE_CREDENTIALS_JSON')