fix(task7): invalidate tokens on password change or reset

This commit is contained in:
Atharv1705
2026-11-17 18:31:45 +05:30
parent b8639bc52a
commit 9276064d18
11 changed files with 145 additions and 4 deletions
+9
View File
@@ -31,6 +31,15 @@ def get_current_user(
user = db.query(User).filter(User.id == user_id).first()
if user is None or not user.is_active:
raise credentials_exception
token_tv = payload.get("tv", 0)
user_tv = getattr(user, "token_version", 0)
if token_tv != user_tv:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Token has been invalidated. Please log in again.",
headers={"WWW-Authenticate": "Bearer"},
)
return user