diff --git a/src/MauiSettings/Helper/MauiSettingsHelper.cs b/src/MauiSettings/Helper/MauiSettingsHelper.cs index 93918e8..e644950 100644 --- a/src/MauiSettings/Helper/MauiSettingsHelper.cs +++ b/src/MauiSettings/Helper/MauiSettingsHelper.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using System.Security; namespace AndreasReitberger.Maui.Helper { @@ -109,7 +110,12 @@ public static void SetSettingsValue(string key, object value) } public static async Task SetSecureSettingsValueAsync(string key, string value) { - await SecureStorage.Default.SetAsync(key, value); + if (string.IsNullOrEmpty(value)) + { + // It's not allowed to set a secure value to an empty string, so remove it. + SecureStorage.Default.Remove(key); + } + else await SecureStorage.Default.SetAsync(key, value); } public static void ClearSettings() diff --git a/src/MauiSettings/MauiSettingsGeneric.cs b/src/MauiSettings/MauiSettingsGeneric.cs index 65da0b9..223fb4f 100644 --- a/src/MauiSettings/MauiSettingsGeneric.cs +++ b/src/MauiSettings/MauiSettingsGeneric.cs @@ -140,6 +140,20 @@ await Task.Run(async delegate await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Save); }); } + public static async Task SaveSecureSettingsAsync() + { + await Task.Run(async delegate + { + await SaveSecureSettingsAsync(settings: SettingsObject); + }); + } + public static async Task SaveSecureSettingsAsync(object settings) + { + await Task.Run(async delegate + { + await GetClassMetaAsync(settings: settings, mode: MauiSettingsActions.Save, secureOnly: true); + }); + } #endregion #region DeleteSettings