api: return HTTP error when not logged in on /api/user-info

This commit is contained in:
lilly 2026-05-14 16:29:37 +02:00
commit 3b3291b6d3
Signed by: lilly
SSH key fingerprint: SHA256:y9T5GFw2A20WVklhetIxG1+kcg/Ce0shnQmbu1LQ37g
2 changed files with 7 additions and 17 deletions

View file

@ -65,22 +65,13 @@ app.add_exception_handler(
async def get_user_info(
req: Request, current_user: deps.CurrentUser
) -> models.UserStatus:
if current_user is None:
return models.UserStatus(
is_logged_in=False,
is_authorized=False,
username=None,
guaranteed_session_until=None,
)
else:
return models.UserStatus(
is_logged_in=True,
is_authorized=current_user.may_operate_locks,
guaranteed_session_until=datetime.fromtimestamp(
current_user.id_token.exp, UTC
),
username=current_user.id_token.preferred_username,
)
return models.UserStatus(
is_authorized=current_user.may_operate_locks,
guaranteed_session_until=datetime.fromtimestamp(
current_user.id_token.exp, UTC
),
username=current_user.id_token.preferred_username,
)
@app.get("/auth/login", tags=["auth"], response_class=RedirectResponse, status_code=302)

View file

@ -41,7 +41,6 @@ class CurrentUser(BaseModel):
class UserStatus(BaseModel):
is_logged_in: bool
is_authorized: bool
guaranteed_session_until: Optional[datetime]
username: Optional[str]