Merge pull request #10609 from abpframework/maliming/AuthenticationStateProviderOnAuthenticationStateChanged

Update `AuthenticationStateProviderOnAuthenticationStateChanged`
pull/10612/head
liangshiwei 4 years ago committed by GitHub
commit 35dafd51b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,12 @@ namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
private List<RenderFragment> ToolbarItemRenders { get; set; } = new List<RenderFragment>();
protected override async Task OnInitializedAsync()
{
await GetToolbarItemRendersAsync();
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async Task GetToolbarItemRendersAsync()
{
var toolbar = await ToolbarManager.GetAsync(StandardToolbars.Main);
@ -33,12 +39,11 @@ namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
builder.CloseComponent();
});
}
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{
await GetToolbarItemRendersAsync();
await InvokeAsync(StateHasChanged);
}

@ -15,35 +15,31 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic
[Inject]
protected IMenuManager MenuManager { get; set; }
[CanBeNull]
protected AuthenticationStateProvider AuthenticationStateProvider;
[Inject]
public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
[CanBeNull]
protected SignOutSessionStateManager SignOutManager;
protected ApplicationMenu Menu { get; set; }
protected override async Task OnInitializedAsync()
{
Menu = await MenuManager.GetAsync(StandardMenus.User);
Navigation.LocationChanged += OnLocationChanged;
LazyGetService(ref AuthenticationStateProvider);
LazyGetService(ref SignOutManager);
if (AuthenticationStateProvider != null)
{
AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e)
{
InvokeAsync(StateHasChanged);
}
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{
Menu = await MenuManager.GetAsync(StandardMenus.User);
@ -53,13 +49,10 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic
public void Dispose()
{
Navigation.LocationChanged -= OnLocationChanged;
if (AuthenticationStateProvider != null)
{
AuthenticationStateProvider.AuthenticationStateChanged -=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
AuthenticationStateProvider.AuthenticationStateChanged -=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async Task NavigateToAsync(string uri, string target = null)
{
if (target == "_blank")

Loading…
Cancel
Save