@page "/Profile" @page "/Profile/General" @using Microsoft.AspNetCore.Components.Authorization @inject UserService UserService @inject IMessageService MessageService @inject AuthenticationStateProvider AuthenticationStateProvider @inject NavigationManager NavigationManager @inject ILogger Logger @attribute [Authorize]
@code { User User = new(); Form Form; protected override async Task OnInitializedAsync() { var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); if (authState.User.Identity.IsAuthenticated) User = await UserService.GetAsync(authState.User.Identity.Name); } private async Task Save() { try { if (Form.IsModified) { await UserService.UpdateAsync(User); MessageService.Success("Profile updated!"); NavigationManager.NavigateTo("/Logout?force=true", true); } } catch (Exception ex) { MessageService.Error("An unknown error occurred."); Logger.LogError(ex, "An unknown error occurred."); } } }