title: How do I correctly notify the Blazor UI that my user state has changed?
body: <p>I am currently learning asp.net core and blazor, and have come across an issue with little documentation. I have a Server side Blazor app and am re doing authentication to use local storage and the ServerAuthenticationStateProvider. This code is based off <a href="https://chrissainty.com/securing-your-blazor-apps-authentication-with-clientside-blazor-using-webapi-aspnet-core-identity/" rel="nofollow noreferrer">this guide</a>, here is my current implementation of the state provider:</p>
  
  <p><strong>MyAuthenticationStateProvider.cs</strong></p>
  
  <pre><code>namespace BlazorApp
  {
      public class MyAuthenticationStateProvider : ServerAuthenticationStateProvider
      {
          private readonly HttpClient _httpClient;
          private readonly ILocalStorageService _localStorage;
  
          public MyAuthenticationStateProvider(HttpClient httpClient, ILocalStorageService localStorage)
          {
              _httpClient = httpClient;
              _localStorage = localStorage;
          }
          public override async Task&lt;AuthenticationState&gt; GetAuthenticationStateAsync()
          {
              var savedToken = await _localStorage.GetItemAsync&lt;string&gt;("authToken");
  
              if (string.IsNullOrWhiteSpace(savedToken))
              {
                  return new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
              }
  
              var user = new ClaimsPrincipal(new ClaimsIdentity(ParseClaimsFromJwt(savedToken), "jwt"));
  
              return new AuthenticationState(user);
          }
  
          public void MarkUserAsAuthenticated(string token)
          {
              var authenticatedUser = new ClaimsPrincipal(new ClaimsIdentity(ParseClaimsFromJwt(token), "jwt"));
              var authState = Task.FromResult(new AuthenticationState(authenticatedUser));
              NotifyAuthenticationStateChanged(authState);
  
          }
  </code></pre>
  
  <p><strong>LoginControl.cs</strong></p>
  
  <pre><code>@page "/loginControl"
  @inject IAuthService AuthService
  @inject NavigationManager NavigationManager
  
      &lt;AuthorizeView&gt;
  
          &lt;Authorized&gt;
  
              &lt;b&gt;Hello, @context.User.Identity.Name!&lt;/b&gt;
  
              &lt;a class="ml-md-auto btn btn-primary"
                 href="logout?returnUrl=/"
                 target="_top"&gt;Logout&lt;/a&gt;
  
          &lt;/Authorized&gt;
  
          &lt;Authorizing&gt;
              &lt;b&gt;Authentication in progress&lt;/b&gt;
          &lt;/Authorizing&gt;
  
          &lt;NotAuthorized&gt;
  
              &lt;input type="text"
                     placeholder="Email"
                     @bind="@email" /&gt;
  
              &amp;nbsp;&amp;nbsp;
  
              &lt;input type="password"
                     placeholder="Password"
                     @bind="@password" /&gt;
  
              &lt;button class="ml-md-auto btn btn-primary"
                      @onclick="@createSession"&gt;
                  Login
              &lt;/button&gt;
  
          &lt;/NotAuthorized&gt;
  
      &lt;/AuthorizeView&gt;
  
  @code {
  
      string email = "";
  
      string password = "";
  
      async void createSession()
      {
  
          var loginRequest = new LoginRequest
          {
  
              Email = email,
              Password = password
  
          };
  
          await AuthService.Login(loginRequest);
      }
  
  }
  </code></pre>
  
  <p>I would expect that after the <code>NotifyAuthenticationStateChanged(AuthState)</code> is called, my login UI would refresh and the <code>&lt;Authorized&gt;</code> content to display. However my UI still shows the <code>&lt;NotAuthorized&gt;</code> content. Did I miss something to do with dispatching to the main thread?? I am Very new to all this but my Mentor mentioned something to do with this possibly having to do with being a background thread not telling the UI to re-render. </p>