refactor(auth): Use user_id as JWT sub and implement get_user_by_id

Switched from username to user_id as the primary identifier in JWT tokens to better support external authentication providers. Added get_user_by_id to HistoryManager and updated API dependencies and tests to reflect these changes.
This commit is contained in:
Yunxiao Xu
2026-02-11 16:41:27 -08:00
parent ceddacf9cb
commit b23fbce8d0
9 changed files with 31 additions and 15 deletions

View File

@@ -39,6 +39,11 @@ class HistoryManager:
result = session.execute(select(User).where(User.username == email))
return result.scalar_one_or_none()
def get_user_by_id(self, user_id: str) -> Optional[User]:
"""Fetch a user by their ID."""
with self.get_session() as session:
return session.get(User, user_id)
def create_user(self, email: str, password: Optional[str] = None, display_name: Optional[str] = None) -> User:
"""Create a new local user."""
hashed_password = ph.hash(password) if password else None