From 43ff1af9e39ce481d61a84564720706bb4a93dca Mon Sep 17 00:00:00 2001 From: valenti Date: Wed, 29 Apr 2026 12:03:48 -0400 Subject: [PATCH] fastcheck_api fix --- fastcheck_api/app/api/dependencies.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fastcheck_api/app/api/dependencies.py b/fastcheck_api/app/api/dependencies.py index 22ee6a8..3813e8f 100644 --- a/fastcheck_api/app/api/dependencies.py +++ b/fastcheck_api/app/api/dependencies.py @@ -4,13 +4,17 @@ from dataclasses import dataclass from typing import Annotated, Any from bson import ObjectId -from fastapi import Depends, Header, HTTPException, Request, status +from fastapi import Depends, HTTPException, Request, status +from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer from motor.motor_asyncio import AsyncIOMotorDatabase from fastcheck_api.app.core.mongodb import get_db from fastcheck_api.app.core.security import AuthError, decode_token +_bearer_scheme = HTTPBearer(auto_error=False) + + @dataclass(frozen=True) class CurrentUser: id: str @@ -21,13 +25,13 @@ class CurrentUser: async def get_current_user( request: Request, - authorization: Annotated[str | None, Header()] = None, + credentials: Annotated[HTTPAuthorizationCredentials | None, Depends(_bearer_scheme)] = None, db: AsyncIOMotorDatabase = Depends(get_db), ) -> CurrentUser: - if not authorization or not authorization.lower().startswith("bearer "): + if credentials is None or not credentials.credentials: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="No token provided") - token = authorization.split(" ", 1)[1].strip() + token = credentials.credentials try: payload = decode_token(token) except AuthError as e: