Merge pull request #10608 from abpframework/AuthenticationStateProviderOnAuthenticationStateChanged

Re-render `NavToolbar` when authentication state has changed.
pull/10609/head
maliming 4 years ago committed by GitHub
commit 5ba755777f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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