ЛР3 — БВТ2301— Бушков — на 4 #105

Closed
zhebush wants to merge 15 commits from zhebush/mtusi2026lab3:solution/bvt2301-bushkov into main
Showing only changes of commit 05d85eaf87 - Show all commits
+8 -3
View File
@@ -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 <token>" и "<token>".
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))