7f06856f45
build-and-deploy / deploy (push) Successful in 10m50s
Blazor UI + ASP.NET API + Postgres; push to main builds images and rolls out namespace tafsirquran.
46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using Microsoft.JSInterop;
|
|
using TafsirQuran.Shared.Services;
|
|
|
|
namespace TafsirQuran.UI.Services;
|
|
|
|
public class BrowserAuthTokenStore(IJSRuntime js) : IAuthTokenStore
|
|
{
|
|
private const string Key = "tq_auth_token";
|
|
private string? _memory;
|
|
private bool _loaded;
|
|
|
|
public async Task<string?> GetTokenAsync()
|
|
{
|
|
if (_loaded) return _memory;
|
|
try
|
|
{
|
|
_memory = await js.InvokeAsync<string?>("tqStorage.get", Key);
|
|
_loaded = true;
|
|
return _memory;
|
|
}
|
|
catch (InvalidOperationException)
|
|
{
|
|
return _memory;
|
|
}
|
|
catch (JSException)
|
|
{
|
|
return _memory;
|
|
}
|
|
}
|
|
|
|
public async Task SetTokenAsync(string? token)
|
|
{
|
|
_memory = token;
|
|
_loaded = true;
|
|
try
|
|
{
|
|
if (string.IsNullOrWhiteSpace(token))
|
|
await js.InvokeVoidAsync("tqStorage.remove", Key);
|
|
else
|
|
await js.InvokeVoidAsync("tqStorage.set", Key, token);
|
|
}
|
|
catch (InvalidOperationException) { }
|
|
catch (JSException) { }
|
|
}
|
|
}
|