import os import firebase_admin from firebase_admin import credentials, firestore from dotenv import load_dotenv; load_dotenv() # Initialize Firebase Admin SDK # Initialize Firebase app with credentials and options cred = credentials.Certificate({ "type": "service_account", "project_id": os.environ.get("FIREBASE_PROJECT_ID"), "private_key_id": os.environ.get("FIREBASE_PRIVATE_KEY_ID"), "private_key": os.environ.get("FIREBASE_PRIVATE_KEY").replace("\\n", "\n"), "client_email": os.environ.get("FIREBASE_CLIENT_EMAIL"), "client_id": os.environ.get("FIREBASE_CLIENT_ID"), "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": os.environ.get("FIREBASE_CLIENT_X509_CERT_URL") }) try: firebase_admin.get_app() except ValueError: firebase_admin.initialize_app(cred, { 'databaseURL': os.environ.get("DATABASE_URL") })