fix: Google Sign-In - Firebase Admin credentials via env var + mobile redirect flow
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
from uuid import uuid4
|
||||
from typing import Annotated, Optional
|
||||
@ -12,11 +13,26 @@ from app.schemas.user import PassengerCreate, Token, UserResponse, LoginRequest,
|
||||
import firebase_admin
|
||||
from firebase_admin import auth as firebase_auth, credentials
|
||||
|
||||
# Initialize Firebase Admin
|
||||
# Initialize Firebase Admin SDK
|
||||
# Supports two methods:
|
||||
# 1. FIREBASE_SERVICE_ACCOUNT_JSON env var with the full JSON as a string (recommended for Render/production)
|
||||
# 2. GOOGLE_APPLICATION_CREDENTIALS env var pointing to a JSON file path (local dev)
|
||||
try:
|
||||
if not firebase_admin._apps:
|
||||
# Default initialization (uses GOOGLE_APPLICATION_CREDENTIALS)
|
||||
firebase_admin.initialize_app()
|
||||
sa_json = os.environ.get("FIREBASE_SERVICE_ACCOUNT_JSON")
|
||||
if sa_json:
|
||||
# Parse the JSON string directly from environment variable
|
||||
sa_dict = json.loads(sa_json)
|
||||
cred = credentials.Certificate(sa_dict)
|
||||
firebase_admin.initialize_app(cred)
|
||||
print("DEBUG: Firebase Admin initialized from FIREBASE_SERVICE_ACCOUNT_JSON env var")
|
||||
elif os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
|
||||
# Use file path from GOOGLE_APPLICATION_CREDENTIALS
|
||||
firebase_admin.initialize_app()
|
||||
print("DEBUG: Firebase Admin initialized from GOOGLE_APPLICATION_CREDENTIALS file")
|
||||
else:
|
||||
print("WARNING: No Firebase credentials found. Set FIREBASE_SERVICE_ACCOUNT_JSON or GOOGLE_APPLICATION_CREDENTIALS.")
|
||||
firebase_admin.initialize_app()
|
||||
except Exception as e:
|
||||
print(f"WARNING: Firebase Admin could not be initialized: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user