From 918c797df480229323c3776bd6e3c5a8978b6abb Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Thu, 25 Jul 2024 23:54:07 +0100 Subject: [PATCH] Allow anonymous creation properly --- src/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.py b/src/main.py index d7f37fd..7bc2c80 100644 --- a/src/main.py +++ b/src/main.py @@ -66,9 +66,11 @@ async def lifespan(_app: FastAPI): yield -async def has_account(req: Request, credentials: HTTPBasicCredentials = Depends(HTTPBasic())) -> db.Account: +async def has_account(req: Request, credentials: HTTPBasicCredentials = Depends(HTTPBasic())) -> db.Account | None: account = await db.Account.get_or_none(username=credentials.username) if account is None: + if os.getenv("ALLOW_ANONYMOUS", "true") == "true": + return raise HTTPException(status_code=401, detail="Invalid credentials", headers={"WWW-Authenticate": "Basic"}) ph = PasswordHasher() try: