diff --git a/app/deps.py b/app/deps.py index 2c590734..dba04b29 100644 --- a/app/deps.py +++ b/app/deps.py @@ -20,10 +20,15 @@ def get_db(): def current_user(request: Request, db: Session = Depends(get_db)) -> User: - auth = request.headers.get("authorization", "") - if not auth.lower().startswith("bearer "): + auth = request.headers.get("authorization", "").strip() + if not auth: raise ApiError(401, "unauthorized", "Требуется Bearer-токен") - token = auth[7:].strip() + # Swagger UI для bearerAuth подставляет токен без префикса "Bearer ". + # Принимаем оба варианта: "Bearer " и "". + if auth.lower().startswith("bearer "): + token = auth[7:].strip() + else: + token = auth if not token: raise ApiError(401, "unauthorized", "Пустой токен") row = db.get(SessionRow, token_hash(token))