From 29838b70462d7d6ea00b7cd990fa47478a78a3b8 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 25 Jul 2024 23:57:48 +0100 Subject: [PATCH] fix http basic requiring --- src/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index 7bc2c80..a666454 100644 --- a/src/main.py +++ b/src/main.py @@ -65,8 +65,12 @@ async def lifespan(_app: FastAPI): ) yield +httpbasic = HTTPBasic(auto_error=False) -async def has_account(req: Request, credentials: HTTPBasicCredentials = Depends(HTTPBasic())) -> db.Account | None: + +async def has_account(req: Request, credentials: HTTPBasicCredentials | None = Depends(httpbasic)) -> db.Account | None: + if os.getenv("ALLOW_ANONYMOUS", "true") == "true" and not credentials: + return account = await db.Account.get_or_none(username=credentials.username) if account is None: if os.getenv("ALLOW_ANONYMOUS", "true") == "true":