| 1234567891011121314151617181920212223242526 |
- using Blazored.SessionStorage;
- using System.Security.Claims;
-
- namespace NemAnBlazor
- {
- public class AuthProvider : AuthenticationStateProvider
- {
- private readonly ISessionStorageService _sessionStorage;
- public AuthProvider(ISessionStorageService sessionStorage)
- {
- _sessionStorage = sessionStorage;
- }
- public override async Task<AuthenticationState> GetAuthenticationStateAsync()
- {
- string token = await _sessionStorage.GetItemAsync<string>("token");
-
- ClaimsIdentity identity = new ();
- ClaimsPrincipal user = new (identity);
- AuthenticationState state = new(user);
-
- NotifyAuthenticationStateChanged(Task.FromResult(state));
-
- return state;
- }
- }
- }
|