From 2e0cda834b8e88d5cfe6499c341ed8956b77e224 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Sun, 1 Mar 2026 16:05:15 +0100 Subject: [PATCH] feat: add get_optional_user for unauthenticated generate access --- backend/app/auth.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/app/auth.py b/backend/app/auth.py index 464566a..6862643 100644 --- a/backend/app/auth.py +++ b/backend/app/auth.py @@ -51,3 +51,15 @@ def get_current_user( if user is None or not user.is_active: raise credentials_exception return user + + +def get_optional_user( + access_token: Optional[str] = Cookie(default=None), + db: Session = Depends(get_db), +) -> Optional[models.User]: + if not access_token: + return None + try: + return get_current_user(access_token=access_token, db=db) + except HTTPException: + return None