This commit is contained in:
Timothy Jaeryang Baek
2026-08-24 17:47:10 -04:00
parent 9e7c9360b7
commit a6834f089b
3 changed files with 27 additions and 5 deletions
+9 -2
View File
@@ -1929,6 +1929,7 @@ class OAuthManager:
if not sub:
log.warning(f'OAuth callback failed, sub is missing: {user_data}')
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED)
sub = str(sub)
oauth_data = {}
oauth_data[provider] = {
@@ -1993,7 +1994,13 @@ class OAuthManager:
user = await Users.get_user_by_email(email, db=db)
if user:
# Update the user with the new oauth sub
await Users.update_user_oauth_by_id(user.id, provider, sub, db=db)
user = await Users.update_user_oauth_by_id(user.id, provider, sub, db=db) or user
if user:
provider_oauth = (user.oauth or {}).get(provider) if isinstance(user.oauth, dict) else None
# Lazy repair for legacy rows that stored numeric provider ids as JSON numbers.
if isinstance(provider_oauth, dict) and provider_oauth.get('sub') != sub:
user = await Users.update_user_oauth_by_id(user.id, provider, sub, db=db) or user
if user:
user = await self.update_user_role_from_oauth(
@@ -2377,7 +2384,7 @@ class OAuthManager:
# 8. Identify users to log out
users_to_logout = []
if sub:
user = await Users.get_user_by_oauth_sub(matched_provider, sub, db=db)
user = await Users.get_user_by_oauth_sub(matched_provider, str(sub), db=db)
if user:
users_to_logout.append(user)