public override async Task <AuthenticationState> GetAuthenticationStateAsync() { if (_accessor.IsServerStarted()) { _token = await _storage.GetAsync <string>(TokenKey); } Console.WriteLine($"Token is {_token}"); if (!string.IsNullOrWhiteSpace(_token)) { var jwtToken = new JwtSecurityToken(_token); if (jwtToken.ValidTo > DateTime.UtcNow) { _httpClientService.SetAuthorization(_token); var identity = new ClaimsIdentity(jwtToken.Claims, AuthenticationType); return(new AuthenticationState(new ClaimsPrincipal(identity))); } } _token = null; if (_accessor.IsServerStarted()) { await _storage.DeleteAsync(TokenKey); } _httpClientService.RemoveAuthorization(); return(new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()))); }
private async Task <T> GetStoredItemOrResetAsync <T>(string key, T defaultValue = default) { try { return(await _localStorageService.GetAsync <T>(key)); } catch { await _localStorageService.DeleteAsync(key); return(defaultValue); } }
public async Task RemoveSavedPlayerIdAsync() { await _preferenceStore.DeleteAsync(PreferredPlayerIdKey); }