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 GetTokenAsync() { if (_loaded) return _memory; try { _memory = await js.InvokeAsync("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) { } } }