Danny Goodall
Danny Goodall

Reputation: 838

Xamarin.Auth AccountStore not deleting values?

Whenever I call my method which removes something from the AccountStore in Xamarin, it deletes it and says that there is one less thing in that list. The method below is called first from the dependency service.

public void DeleteSecureValue(string appName, string key)
{
    var account = AccountStore.Create().FindAccountsForService(appName).FirstOrDefault();
    if (account.Properties.ContainsKey(key))
        account.Properties.Remove(key);

    var props = account.Properties;
    // when debugging, props doesn't contain a value for passcode
}

Xamarin.Forms.DependencyService.Get<IStorageHandler>().DeleteSecureValue(GlobalConstants.APP_NAME, "passcode");

var account = AccountStore.Create().FindAccountsForService(GlobalConstants.APP_NAME).FirstOrDefault();
var props = account.Properties;
// when debugging, props now has a value for passcode when it shouldn't

Why does the value for passcode seem to come back?

Upvotes: 3

Views: 1373

Answers (1)

Sven-Michael St&#252;be
Sven-Michael St&#252;be

Reputation: 14750

You are just manipulating a Dictionary in memory in DeleteSecureValue. You have to write your changes back to your storage.

public void DeleteSecureValue(string appName, string key)
{
    var store = AccountStore.Create();
    var account = AccountStore.Create().FindAccountsForService(appName).FirstOrDefault();
    if (account.Properties.ContainsKey(key))
    {
        account.Properties.Remove(key);
        store.Save(account, appName);
    }
}

Upvotes: 7

Related Questions