🐛 fix(chat.py): close websocket connection with status code 1008 and reason "Unauthorized" if user is not authenticated or inactive

🐛 fix(auth/utils.py): raise credentials_exception if token has expired
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-30 17:29:07 -03:00
commit eacf558e70
2 changed files with 18 additions and 3 deletions

View file

@ -88,6 +88,10 @@ async def get_current_user(
)
user_id: UUID = payload.get("sub") # type: ignore
token_type: str = payload.get("type") # type: ignore
if expires := payload.get("exp", None):
expires_datetime = datetime.fromtimestamp(expires)
if datetime.now(timezone.utc) > expires_datetime:
raise credentials_exception
if user_id is None or token_type:
raise credentials_exception