22@* Issue: Cannot provide a value for property 'AccountService' on type
33'CashFlowAnalyzer.Client.Layout.MainLayout'. There is no registered
44service of type 'CashFlowAnalyzer.Client.Services.AccountService'. *@
5- @* @ inject NavigationManager Navigation
6- @inject AccountService AccountService
7- @inject AuthenticationStateProvider AuthenticationStateProvider *@
5+ @inject NavigationManager Navigation
6+ @inject IAccountService AccountService
7+ @inject AuthenticationInfoProvider AuthenticationInfoProvider
88
99<div class =" page" >
1010 <div class =" sidebar" >
@@ -13,10 +13,10 @@ service of type 'CashFlowAnalyzer.Client.Services.AccountService'. *@
1313
1414 <main >
1515 <div class =" top-row px-4" >
16- @* @ if (isAuthenticated)
16+ @if (isAuthenticated )
1717 {
1818 <button class =" btn btn-danger" @onclick =" Logout" >Logout </button >
19- } *@
19+ }
2020 <a href =" https://learn.microsoft.com/aspnet/core/" target =" _blank" >About</a >
2121 </div >
2222
@@ -32,18 +32,25 @@ service of type 'CashFlowAnalyzer.Client.Services.AccountService'. *@
3232 <span class =" dismiss" >🗙</span >
3333</div >
3434
35- @* @ code {
35+ @code {
3636 private bool isAuthenticated ;
3737
38- protected override async Task OnInitializedAsync( )
38+ protected override async Task OnAfterRenderAsync ( bool firstRender )
3939 {
40- var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
41- isAuthenticated = authState.User.Identity.IsAuthenticated;
40+ if (firstRender )
41+ {
42+ isAuthenticated = await AuthenticationInfoProvider .IsAuthenticated ();
43+ if (isAuthenticated )
44+ {
45+ StateHasChanged ();
46+ }
47+ }
48+ await base .OnAfterRenderAsync (firstRender );
4249 }
4350
4451 private async Task Logout ()
4552 {
4653 await AccountService .Logout ();
4754 Navigation .NavigateTo (" /Login" );
4855 }
49- } *@
56+ }
0 commit comments