Populate email on login for users with empty email field

When a user already exists in the DB, get_or_create_from_azure was
returning early without updating their email from Azure AD claims.
Users created before email sync was in place would permanently show
empty emails in User Management.

Now syncs email from Azure AD claims on each login if the stored
email is empty.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-03-03 15:45:48 +00:00
parent d7fd435210
commit c6f7b0d5f1

View file

@ -42,6 +42,10 @@ class UserRepository:
"""Get existing user or create new one from Azure AD claims."""
user = await self.get_by_azure_oid(azure_ad_oid)
if user:
# Sync email from Azure AD if not yet stored
if not user.email and email:
user.email = email
await self.session.flush()
return user
# Create new user