pyjwt will auto check exp

pull/21891/head
ytqh 1 year ago
parent d32779b5a8
commit b3a188e8a1

@ -55,17 +55,12 @@ def validate_user_token_and_extract_info(view: Optional[Callable] = None):
try: try:
decoded = PassportService().verify(auth_token) decoded = PassportService().verify(auth_token)
user_id = decoded.get("user_id") user_id = decoded.get("user_id")
expired_at = decoded.get("exp")
except Exception as e: except Exception as e:
raise Unauthorized(f"Failed to extract user_id from token: {str(e)}") raise Unauthorized(f"Failed to extract user_id from token: {str(e)}")
if not user_id: if not user_id:
raise Unauthorized("Invalid token: missing user_id") raise Unauthorized("Invalid token: missing user_id")
if expired_at < datetime.now(UTC).timestamp():
raise Unauthorized("Token has expired")
account = AccountService.load_user(user_id) account = AccountService.load_user(user_id)
if account is None: if account is None:
raise Unauthorized("Invalid token: user not found") raise Unauthorized("Invalid token: user not found")

Loading…
Cancel
Save