public void EndSession() { IsSessionStarted = false; UserId = DepartmentId = null; DepartmentName = Name = Email = null; AuthenticationStateChanged?.Invoke(IsSessionStarted); }
/// <summary> /// Raises the <see cref="AuthenticationStateChanged"/> event. /// </summary> /// <param name="task">A <see cref="Task"/> that supplies the updated <see cref="AuthenticationState"/>.</param> protected void NotifyAuthenticationStateChanged(Task <AuthenticationState> task) { if (task == null) { throw new ArgumentNullException(nameof(task)); } AuthenticationStateChanged?.Invoke(task); }
public void StartSession(SignInResult signInResult) { UserId = signInResult.UserId; Name = signInResult.Name; Email = signInResult.Email; DepartmentId = signInResult.DepartmentId; DepartmentName = signInResult.DepartmentName; IsSessionStarted = true; AuthenticationStateChanged?.Invoke(IsSessionStarted); }
public async Task Logout() { using var scope = serviceProvider.CreateScope(); var localStorage = scope.ServiceProvider.GetRequiredService <ILocalStorageService>(); var authStateProvider = scope.ServiceProvider.GetRequiredService <AuthenticationStateProvider>(); await localStorage.RemoveItemAsync(StorageAuthTokenKey); if (authStateProvider is ApiAuthenticationStateProvider apiAuthenticationStateProvider) { apiAuthenticationStateProvider.UpdateAuthenticationState(); } AuthenticationStateChanged?.Invoke(this, new EventArgs()); }
private async Task UpdateToken(IServiceScope scope, ApiResponse <AuthResponse> result, HttpResponseMessage httpResponse, string username = null) { var localStorage = scope.ServiceProvider.GetRequiredService <ILocalStorageService>(); var authStateProvider = scope.ServiceProvider.GetRequiredService <AuthenticationStateProvider>(); if (httpResponse.IsSuccessStatusCode) { await localStorage.SetItemAsync(StorageAuthTokenKey, result.Data.Token); if (username != null) { await localStorage.SetItemAsync(StorageAuthUsernameKey, username); } if (authStateProvider is ApiAuthenticationStateProvider apiAuthenticationStateProvider) { apiAuthenticationStateProvider.UpdateAuthenticationState(); } AuthenticationStateChanged?.Invoke(this, new EventArgs()); } }
protected virtual void OnAuthenticationStateChanged() { AuthenticationStateChanged?.Invoke(this, EventArgs.Empty); }
protected virtual void OnAuthenticationChanged() { AuthenticationStateChanged.Invoke(_authenticationState); }
protected virtual void OnAuthenticationStateChanged() { AuthenticationStateChanged?.Invoke(); }