fix: sync user name from external auth API and fix audit log schema

- Auth router: Extract user name from nested data.userInfo.name structure
- Auth router: Sync user name on every login (not just on user creation)
- Audit schema: Change changes field type to Optional[Any] to support
  both list and dict formats (fixes 500 error on audit page)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2026-01-10 10:12:35 +08:00
parent 55f85d0d3c
commit 96210c7ad4
2 changed files with 12 additions and 2 deletions

View File

@@ -76,16 +76,26 @@ async def login(
# Find or create user in local database
user = db.query(User).filter(User.email == login_request.email).first()
# Get name from auth API response (nested in data.userInfo.name)
user_info = auth_result.get("data", {}).get("userInfo", {})
auth_name = user_info.get("name", login_request.email.split("@")[0])
if not user:
# Create new user based on auth API response
user = User(
email=login_request.email,
name=auth_result.get("name", login_request.email.split("@")[0]),
name=auth_name,
is_active=True,
)
db.add(user)
db.commit()
db.refresh(user)
else:
# Sync user name from external auth system on each login
if user.name != auth_name:
user.name = auth_name
db.commit()
db.refresh(user)
if not user.is_active:
raise HTTPException(