diff --git a/Storage/Storage/LCUser.cs b/Storage/Storage/LCUser.cs index af1aa03..70e8f28 100644 --- a/Storage/Storage/LCUser.cs +++ b/Storage/Storage/LCUser.cs @@ -326,7 +326,7 @@ namespace LeanCloud.Storage { if (string.IsNullOrEmpty(platform)) { throw new ArgumentNullException(nameof(platform)); } - return LinkWithAuthData(platform, null); + return UnlinkWithAuthData(platform); } /// @@ -523,11 +523,34 @@ namespace LeanCloud.Storage { return new LCQuery(CLASS_NAME); } - Task LinkWithAuthData(string authType, Dictionary data) { + async Task LinkWithAuthData(string authType, Dictionary data) { + Dictionary oriAuthData = new Dictionary(AuthData); AuthData = new Dictionary { { authType, data } }; - return Save(); + try { + await Save(); + oriAuthData.Add(authType, data); + AuthData = oriAuthData; + } catch (Exception e) { + AuthData = oriAuthData; + throw e; + } + } + + async Task UnlinkWithAuthData(string authType) { + Dictionary oriAuthData = new Dictionary(AuthData); + AuthData = new Dictionary { + { authType, null } + }; + try { + await Save(); + oriAuthData.Remove(authType); + AuthData = oriAuthData; + } catch (Exception e) { + AuthData = oriAuthData; + throw e; + } } static async Task Login(Dictionary data) {