Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 2f0ce9c

Browse files
Login and account switching fixes
1 parent 35d79cb commit 2f0ce9c

7 files changed

Lines changed: 19 additions & 33 deletions

File tree

Alidade.Osm/Models/Api/Auth/OsmUserInfo.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ namespace Alidade.Osm.Models.Api.Auth;
44
/// Basic profile information returned by the OSM API after a successful login.
55
/// </summary>
66
/// <param name="UserName">The user's OSM display name.</param>
7-
/// <param name="AvatarUrl">The URL of the user's avatar image, if set.</param>
87
/// <param name="UserId">The numeric OSM user ID.</param>
9-
public record OsmUserInfo(string UserName, string? AvatarUrl, long UserId);
8+
public record OsmUserInfo(string UserName, long UserId);

Alidade.Osm/Models/Api/Auth/StoredAccount.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ namespace Alidade.Osm.Models.Api.Auth;
66
/// </summary>
77
/// <param name="Username">The user's OSM display name.</param>
88
/// <param name="UserId">The numeric OSM user ID.</param>
9-
/// <param name="AvatarUrl">The URL of the user's avatar image, if set.</param>
109
/// <param name="Token">The OAuth 2.0 bearer token for this account.</param>
11-
public record StoredAccount(string Username, long UserId, string? AvatarUrl, string Token);
10+
public record StoredAccount(string Username, long UserId, string Token);

Alidade.Osm/Services/OsmOAuthClient.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ public async Task<string> ExchangeCodeAsync(string tokenEndpoint, string clientI
7676

7777
return new OsmUserInfo(
7878
user.GetProperty("display_name").GetString() ?? string.Empty,
79-
user.TryGetProperty("img", out JsonElement img)
80-
? img.GetProperty("href").GetString()
81-
: null,
8279
user.GetProperty("id").GetInt64());
8380
}
8481

Alidade/Components/Dialogs/SelectAccountDialog.razor

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,10 @@
88
{
99
bool isActive = authState.State.User?.UserId == account.UserId;
1010
<button class="account-row @(isActive ? "account-row-active" : null)"
11-
@onclick="() => Select(account)"
12-
disabled="@isActive">
13-
@if (account.AvatarUrl is not null)
14-
{
15-
<img class="account-avatar" src="@account.AvatarUrl" alt="" />
16-
}
17-
else
18-
{
19-
<div class="account-avatar account-avatar-placeholder">
20-
@account.Username[0]
21-
</div>
22-
}
11+
@onclick="() => Select(account)" disabled="@isActive">
2312
<span class="account-name">@account.Username</span>
24-
@if (isActive)
25-
{
26-
<span class="account-active-badge">Active</span>
27-
}
2813
</button>
14+
<br />
2915
}
3016
</div>
3117
</ChildContent>

Alidade/Components/Panels/SettingsPanel.razor

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
</option>
2121
}
2222
</select>
23-
<button class="account-switcher-btn" @onclick="OpenAccountSwitcher" title="Switch account">
23+
<button class="account-switcher-btn" @onclick="OnAccountButtonClicked">
2424
@if (authState.State.IsLoggedIn)
2525
{
26-
@if (authState.State.User!.AvatarUrl is string avatarUrl)
27-
{
28-
<img class="account-switcher-avatar" src="@avatarUrl" alt="" />
29-
}
30-
<span>@authState.State.User!.UserName</span>
26+
<span>Switch account</span>
3127
}
3228
else
3329
{
34-
<span>Login</span>
30+
<span>Log in</span>
3531
}
3632
</button>
3733
</div>

Alidade/Components/Panels/SettingsPanel.razor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ private void OnEndpointChanged(ChangeEventArgs e)
6060
}
6161
}
6262

63-
private void OpenAccountSwitcher()
64-
=> _ = mediator.Send(new OpenAccountSwitcher.Command());
63+
private void OnAccountButtonClicked()
64+
{
65+
if (authState.State.IsLoggedIn)
66+
{
67+
_ = mediator.Send(new OpenAccountSwitcher.Command());
68+
}
69+
else
70+
{
71+
_ = mediator.Send(new BeginLogin.Command());
72+
}
73+
}
6574

6675
#endregion
6776

Alidade/Services/AuthService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public async Task OnOAuthCallbackAsync(string code, string verifier)
128128
}
129129

130130
OsmUserInfo user = authState.State.User!;
131-
StoredAccount newAccount = new(user.UserName, user.UserId, user.AvatarUrl, token);
131+
StoredAccount newAccount = new(user.UserName, user.UserId, token);
132132

133133
List<StoredAccount> accounts = await storage.GetStoredAccountsAsync(endpoint);
134134
accounts.RemoveAll(a => a.UserId == newAccount.UserId);

0 commit comments

Comments
 (0)