This commit is contained in:
Logan Cusano
2025-07-13 15:26:18 -04:00
parent eb0d6fcf5c
commit ecd2631eec
4 changed files with 64 additions and 38 deletions

View File

@@ -1,14 +1,15 @@
from fastapi import Depends, HTTPException, status
from fastapi.security import OAuth2PasswordBearer
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from firebase_admin import auth
from .firebase_config import get_db
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/token")
http_bearer_scheme = HTTPBearer()
async def get_current_user(token: str = Depends(oauth2_scheme)):
async def get_current_user(credentials: HTTPAuthorizationCredentials = Depends(http_bearer_scheme)):
"""
Verifies the Firebase ID token and retrieves the user document from Firestore.
"""
token = credentials.credentials
try:
decoded_token = auth.verify_id_token(token)
uid = decoded_token['uid']