api: return HTTP error when not logged in on /api/user-info
This commit is contained in:
parent
2f991a6b02
commit
3b3291b6d3
2 changed files with 7 additions and 17 deletions
|
|
@ -65,16 +65,7 @@ app.add_exception_handler(
|
||||||
async def get_user_info(
|
async def get_user_info(
|
||||||
req: Request, current_user: deps.CurrentUser
|
req: Request, current_user: deps.CurrentUser
|
||||||
) -> models.UserStatus:
|
) -> models.UserStatus:
|
||||||
if current_user is None:
|
|
||||||
return models.UserStatus(
|
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,
|
is_authorized=current_user.may_operate_locks,
|
||||||
guaranteed_session_until=datetime.fromtimestamp(
|
guaranteed_session_until=datetime.fromtimestamp(
|
||||||
current_user.id_token.exp, UTC
|
current_user.id_token.exp, UTC
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ class CurrentUser(BaseModel):
|
||||||
|
|
||||||
|
|
||||||
class UserStatus(BaseModel):
|
class UserStatus(BaseModel):
|
||||||
is_logged_in: bool
|
|
||||||
is_authorized: bool
|
is_authorized: bool
|
||||||
guaranteed_session_until: Optional[datetime]
|
guaranteed_session_until: Optional[datetime]
|
||||||
username: Optional[str]
|
username: Optional[str]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue