//----------------------------------------------------------------------- // // Copyright (c) lanedirt. All rights reserved. // Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information. // //----------------------------------------------------------------------- namespace AliasVault.Admin.Auth.Pages; using AliasServerDb; using AliasVault.Admin.Main.Components.Alerts; using AliasVault.Admin.Services; using AliasVault.Auth; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Authorization; using Microsoft.AspNetCore.Identity; /// /// Base auth page that all pages that are part of the auth (non-logged in part of website) should inherit from. /// All pages that inherit from this class will require the user to be logged out. If user is logged in they /// are automatically redirected to index page. /// public class AuthBase : OwningComponentBase { /// /// Gets or sets the logger. /// [Inject] protected ILogger Logger { get; set; } = null!; /// /// Gets or sets the navigation service. /// [Inject] protected NavigationService NavigationService { get; set; } = null!; /// /// Gets or sets the sign in manager. /// [Inject] protected SignInManager SignInManager { get; set; } = null!; /// /// Gets or sets the user manager. /// [Inject] protected UserManager UserManager { get; set; } = null!; /// /// Gets or sets the authentication state provider. /// [Inject] protected AuthenticationStateProvider AuthenticationStateProvider { get; set; } = null!; /// /// Gets or sets the auth logging service. /// [Inject] protected AuthLoggingService AuthLoggingService { get; set; } = null!; /// /// Gets or sets object which holds server validation errors to show in the UI. /// protected ServerValidationErrors ServerValidationErrors { get; set; } = new(); /// protected override async Task OnInitializedAsync() { var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); var user = authState.User; // Redirect to home if the user is already authenticated if (SignInManager.IsSignedIn(user)) { NavigationService.RedirectTo("./"); } } }