fix AuthState
This commit is contained in:
parent
08b4edd1a5
commit
bb00aa8a11
|
|
@ -22,21 +22,23 @@
|
|||
Spieltage
|
||||
</MudNavLink>
|
||||
|
||||
<MudNavLink Href="/persons"
|
||||
Match="NavLinkMatch.Prefix"
|
||||
Icon="@Icons.Material.Filled.Groups">
|
||||
Personen
|
||||
</MudNavLink>
|
||||
|
||||
|
||||
@if (AuthState.Value.IsClubEditor || AuthState.Value.IsSuperAdmin)
|
||||
{
|
||||
<MudNavGroup Title="Stammdaten"
|
||||
Icon="@Icons.Material.Filled.Settings"
|
||||
Expanded="false">
|
||||
<MudNavLink Href="/persons"
|
||||
Match="NavLinkMatch.Prefix"
|
||||
Icon="@Icons.Material.Filled.Groups">
|
||||
Personen
|
||||
</MudNavLink>
|
||||
|
||||
<MudNavLink Href="/expenses"
|
||||
Match="NavLinkMatch.Prefix"
|
||||
Icon="@Icons.Material.Filled.Receipt">
|
||||
Kostenvorlagen
|
||||
Strafen
|
||||
</MudNavLink>
|
||||
</MudNavGroup>
|
||||
}
|
||||
|
|
@ -70,7 +72,7 @@
|
|||
@* Profile - visible to all authenticated users *@
|
||||
@if (AuthState.Value.IsAuthenticated)
|
||||
{
|
||||
<MudNavLink Href="/profile"
|
||||
<MudNavLink Href="/account/profile"
|
||||
Match="NavLinkMatch.Prefix"
|
||||
Icon="@Icons.Material.Filled.Person">
|
||||
Profil
|
||||
|
|
@ -79,6 +81,5 @@
|
|||
</MudNavMenu>
|
||||
|
||||
@code {
|
||||
private bool HasSelectedClub => ClubState.Value.SelectedClub != null ||
|
||||
AuthState.Value.CurrentUser?.ClubMemberships?.Any(c => c.IsDefault) == true;
|
||||
private bool HasSelectedClub => AuthState.Value.CurrentClub != null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,9 @@
|
|||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService DialogService
|
||||
|
||||
<PageTitle>Kosten-Vorlagen</PageTitle>
|
||||
<PageTitle>Strafen-Vorlagen</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h4" Class="mb-4">Kosten-Vorlagen</MudText>
|
||||
<MudText Typo="Typo.h4" Class="mb-4">Strafen-Vorlagen</MudText>
|
||||
|
||||
@if (ExpenseState.Value.Error is not null)
|
||||
{
|
||||
|
|
@ -145,7 +145,7 @@
|
|||
|
||||
private async Task OpenCreateDialog()
|
||||
{
|
||||
var dialog = await DialogService.ShowAsync<ExpenseEditDialog>("Neue Kosten-Vorlage");
|
||||
var dialog = await DialogService.ShowAsync<ExpenseEditDialog>("Neue Strafen-Vorlage");
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result != null && !result.Canceled && result.Data is CreateExpenseDto dto)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Koogle.Application;
|
|||
using Koogle.Infrastructure;
|
||||
using Koogle.Infrastructure.Security;
|
||||
using Koogle.Web.Components;
|
||||
using Koogle.Web.Store.AuthState;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using MudBlazor.Services;
|
||||
|
|
@ -32,6 +33,7 @@ builder.Services.AddFluxor(options =>
|
|||
options.UseReduxDevTools();
|
||||
#endif
|
||||
});
|
||||
builder.Services.AddScoped<AuthEffects>();
|
||||
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Fluxor;
|
||||
using Koogle.Application.DTOs;
|
||||
using Koogle.Application.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
|
|
@ -53,10 +54,10 @@ namespace Koogle.Web.Store.AuthState
|
|||
// Merge Identity roles with club-specific roles for current club
|
||||
var roles = currentUser.Identity.Roles.ToList();
|
||||
var currentClubId = _currentClubContext.ClubId;
|
||||
|
||||
UserClubMembershipDto ? clubMembership = null;
|
||||
if (currentClubId != Guid.Empty)
|
||||
{
|
||||
var clubMembership = currentUser.ClubMemberships
|
||||
clubMembership = currentUser.ClubMemberships
|
||||
.FirstOrDefault(m => m.ClubId == currentClubId);
|
||||
|
||||
if (clubMembership != null)
|
||||
|
|
@ -72,7 +73,7 @@ namespace Koogle.Web.Store.AuthState
|
|||
}
|
||||
}
|
||||
|
||||
dispatcher.Dispatch(new AuthState.InitializeAuthSuccessAction(currentUser, roles));
|
||||
dispatcher.Dispatch(new AuthState.InitializeAuthSuccessAction(currentUser, clubMembership, roles));
|
||||
|
||||
_logger.LogInformation("Auth initialized for user {DisplayName} with roles {Roles}",
|
||||
currentUser.DisplayName, string.Join(", ", roles));
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ public static class AuthReducers
|
|||
{
|
||||
IsLoading = false,
|
||||
IsAuthenticated = true,
|
||||
CurrentUser = action.User
|
||||
CurrentUser = action.User,
|
||||
CurrentClub = action.CurrentClub
|
||||
},
|
||||
action.Roles);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ public record AuthState
|
|||
/// </summary>
|
||||
public UserDto? CurrentUser { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The current user's at login selected club membership.
|
||||
/// </summary>
|
||||
public UserClubMembershipDto? CurrentClub { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The current user's roles.
|
||||
/// </summary>
|
||||
|
|
@ -73,6 +78,7 @@ public record AuthState
|
|||
public static AuthState Initial => new()
|
||||
{
|
||||
CurrentUser = null,
|
||||
CurrentClub = null,
|
||||
IsSuperAdmin = false,
|
||||
IsClubAdmin = false,
|
||||
IsClubEditor = false,
|
||||
|
|
@ -119,6 +125,7 @@ public record AuthState
|
|||
/// <param name="CompanyIds">IDs of accessible companies.</param>
|
||||
public record InitializeAuthSuccessAction(
|
||||
UserDto User,
|
||||
UserClubMembershipDto? CurrentClub,
|
||||
IReadOnlyList<string> Roles);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue