diff --git a/Wave/Components/Pages/ArticleEditor.razor b/Wave/Components/Pages/ArticleEditor.razor index 1f72762..f1ec96f 100644 --- a/Wave/Components/Pages/ArticleEditor.razor +++ b/Wave/Components/Pages/ArticleEditor.razor @@ -6,6 +6,7 @@ @using System.Security.Claims @rendermode @(new InteractiveServerRenderMode(true)) +@attribute [Authorize(Policy = "ArticleEditPermissions")] @inject UserManager UserManager @inject IStringLocalizer Localizer @@ -36,18 +37,22 @@ [CascadingParameter(Name = "TitlePostfix")] private string TitlePostfix { get; set; } = default!; [CascadingParameter] - private Task? AuthenticationState { get; set; } + private Task AuthenticationState { get; set; } = default!; [Parameter] public Guid? Id { get; set; } private ApplicationUser? User { get; set; } private ClaimsPrincipal? ClaimsUser { get; set; } - - protected override async Task OnInitializedAsync() { - if (AuthenticationState is null) throw new ApplicationException("???"); - var state = await AuthenticationState; - ClaimsUser = state.User; - var user = await UserManager.GetUserAsync(state.User); - User = user ?? throw new ApplicationException("???2"); + + protected override async Task OnAfterRenderAsync(bool firstRender) { + if (firstRender) { + if (User is not null) return; + var state = await AuthenticationState; + ClaimsUser = state.User; + var user = await UserManager.GetUserAsync(state.User); + User = user ?? throw new ApplicationException("???2"); + await InvokeAsync(StateHasChanged); + } } + } diff --git a/Wave/Components/Pages/Partials/ArticleEditorPartial.razor b/Wave/Components/Pages/Partials/ArticleEditorPartial.razor index 78917ae..d07f9a9 100644 --- a/Wave/Components/Pages/Partials/ArticleEditorPartial.razor +++ b/Wave/Components/Pages/Partials/ArticleEditorPartial.razor @@ -128,7 +128,8 @@ protected override async Task OnInitializedAsync() { await using var context = await ContextFactory.CreateDbContextAsync(); - Categories = await context.Set().IgnoreQueryFilters().OrderBy(c => c.Color).ToListAsync(); + if (Categories.Count < 1) + Categories = await context.Set().IgnoreQueryFilters().OrderBy(c => c.Color).ToListAsync(); Article? article = null; if (Id is not null) {