Skip to content

Commit

Permalink
Add error catching to the logout function
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed May 8, 2024
1 parent 85047ad commit ab66f7f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions api/routes/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,13 @@ async def create_group_token(group_token_request: GroupTokenRequest,
async def logout(response: Response):
"""Logout the active user"""

response.delete_cookie(key="Authorization")
return response
try:
response.delete_cookie(key="Authorization")

except KeyError:
return {"status": "error", "message": "User is not logged in"}

return {"status": "success"}


@router.get("/groups")
Expand All @@ -318,6 +323,9 @@ async def get_security_groups(groups: list[int] = Depends(get_groups)):
async def read_users_me(user_token_data: TokenData = Depends(get_user_token_from_cookie)):
"""Return JWT content"""

if user_token_data is None:
raise HTTPException(status_code=401, detail="User not found")

engine = db.get_engine()
async_session = db.get_async_session(engine)

Expand Down

0 comments on commit ab66f7f

Please sign in to comment.