Files
gpw_next/GPW.CORE.Smart8.Client/Components/Compo/UserBootstrapClient.razor
T

34 lines
1.0 KiB
Plaintext

@rendermode InteractiveWebAssembly
@inject IJSRuntime JS
@inject GPW.CORE.Services.UserStateService UState
@inject ILogger<UserBootstrapClient> Log
@code {
private readonly Guid _instanceId = Guid.NewGuid();
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
Log.LogInformation("UserBootstrapClient OnAfterRenderAsync instance {Id}", _instanceId);
try
{
var json = await JS.InvokeAsync<string>("localStorage.getItem", "currUser");
if (!string.IsNullOrEmpty(json))
{
var user = System.Text.Json.JsonSerializer.Deserialize<UserDTO>(json);
if (user != null)
{
Log.LogInformation("UserBootstrapClient setting user in instance {Id}", _instanceId);
UState.SetUser(user);
}
}
}
catch (Exception ex)
{
Log.LogError(ex, "UserBootstrapClient error instance {Id}", _instanceId);
}
}
}