You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and given a custom AuthenticationService which I can set some authentication state and raise the authentication state changed event:
public class CustomAuthService // ... derived from RemoveAuthenticationService etc.
{
public void SetAuthenticationState()
{
var principal = // set some claims principal in state somewhere
NotifyAuthenticationStateChanged(Task.Run(() => new AuthenticationState(principal)));
}
}
and a basic non-authenticated (anon) page:
@page "/some-url"
@code
{
[Inject]
public CustomAuthService CustomAuthService { get; set; }
protected override async Task OnInitializedAsync()
{
Console.WriteLine($"Page OnInit {GetHashCode()}");
// Set the auth state
CustomAuthService.SetAuthenticationState();
}
}
When I execute this code - which moves the authentication from Not Authenticated to Authenticated, the Page Component gets created again and the OnInit fires for a second time.
Is there a reason for this? I have been through the CascadingAuthenticationState, Router and various Blazor components but couldn't find any logic which causes the render tree to drop the first instance and create a new one.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Given this App.razor
and given a custom AuthenticationService which I can set some authentication state and raise the authentication state changed event:
and a basic non-authenticated (anon) page:
When I execute this code - which moves the authentication from Not Authenticated to Authenticated, the Page Component gets created again and the OnInit fires for a second time.
Is there a reason for this? I have been through the CascadingAuthenticationState, Router and various Blazor components but couldn't find any logic which causes the render tree to drop the first instance and create a new one.
Beta Was this translation helpful? Give feedback.
All reactions