TourIAm/TIAMWebApp/Client/Services/SecureStorageHandler.cs

53 lines
1.4 KiB
C#

using AyCode.Interfaces.StorageHandlers;
using Blazored.LocalStorage;
using TIAM.Core.Consts;
namespace TIAMWebApp.Client.Services
{
public class SecureStorageHandler : ISecureStorageHandler
{
private readonly SessionStorageAccessor ssa;
private readonly ILocalStorageService localStoragService;
public SecureStorageHandler(SessionStorageAccessor ssa, ILocalStorageService localStorageService)
{
this.ssa = ssa;
this.localStoragService = localStorageService;
}
public async Task SaveToSecureStorageAsync(string key, string value)
{
await localStoragService.SetItemAsync(key, value);
//await ssa.SetValueAsync(key, value);
}
public async Task<string> GetFromSecureStorageAsync(string key)
{
var result = await localStoragService.GetItemAsync<string>(key);
if (result != null)
{
return result;
}
else return string.Empty;
//return await ssa.GetValueAsync<string>(key);
}
public async Task DeleteFromSecureStorageAsync(string key)
{
await localStoragService.RemoveItemAsync(key);
//await ssa.RemoveAsync(key);
}
public async Task ClearAllSecureStorageAsync()
{
await localStoragService.ClearAsync();
//await ssa.Clear();
}
}
}