Skip to content

UserProfile Name/Email not populated on mobile after login #162

@davidortinau

Description

@davidortinau

Problem

When logging into the mobile app, the UserProfile in local SQLite has empty Name and Email fields, even though the webapp (which reads from Identity claims) shows them correctly. The user logs in with the same credentials on both platforms.

Root Cause

The mobile login flow (IdentityAuthService.StoreTokens) sets active_profile_id from the auth response but never populates UserProfile.Name or UserProfile.Email from the JWT claims or auth response. The UserProfileRepository.GetOrCreateDefaultAsync() creates profiles with empty strings for these fields.

The webapp gets name/email from ClaimsPrincipal (server-side Identity), so it never has this problem. But the mobile app relies entirely on the local SQLite UserProfile row, which is never backfilled from auth data.

Expected Behavior

After login on mobile, the local UserProfile should have its Name and Email populated from the auth response (JWT claims contain both ClaimTypes.Email and ClaimTypes.Name). CoreSync should also sync profile changes bidirectionally so edits on either platform propagate.

Steps to Reproduce

  1. Register on webapp (name and email populated via Identity)
  2. Login on mobile app with same credentials
  3. Go to Profile page on mobile - Name and Email are empty
  4. Compare to webapp Profile page - Name and Email are correct

Suggested Fix

In IdentityAuthService.StoreTokens(), after setting active_profile_id, extract name/email from the JWT and update the local UserProfile if those fields are empty:

// After setting active_profile_id
var profile = await _userProfileRepo.GetAsync();
if (profile != null && string.IsNullOrEmpty(profile.Name))
{
    var nameFromJwt = ExtractUserNameFromJwt(response.Token);
    var emailFromJwt = new JwtSecurityToken(response.Token)
        .Claims.FirstOrDefault(c => c.Type == ClaimTypes.Email)?.Value;
    await _userProfileRepo.SaveAsync(profile);
}

Context

Discovered during production data recovery (Postgres wipe incident). UserProfile row existed in SQLite with correct ID but empty Name/Email because it was created by GetOrCreateDefaultAsync() without auth data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions