Browse Source

Re-render `NavToolbar` when authentication state has changed.

pull/10608/head
maliming 5 years ago
parent
commit
d4d2e11c92
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 21
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/NavToolbar.razor.cs

21
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/NavToolbar.razor.cs

@ -1,15 +1,21 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
{
public partial class NavToolbar
public partial class NavToolbar : IDisposable
{
[Inject]
private IToolbarManager ToolbarManager { get; set; }
[Inject]
private AuthenticationStateProvider AuthenticationStateProvider { get; set; }
private List<RenderFragment> ToolbarItemRenders { get; set; } = new List<RenderFragment>();
protected override async Task OnInitializedAsync()
@ -27,7 +33,18 @@ namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
builder.CloseComponent();
});
}
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{
await InvokeAsync(StateHasChanged);
}
public void Dispose()
{
AuthenticationStateProvider.AuthenticationStateChanged -= AuthenticationStateProviderOnAuthenticationStateChanged;
}
}
}

Loading…
Cancel
Save