refac
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user