Skip to content

Commit

Permalink
fix: roll back when auth failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
onerain88 committed Jan 12, 2021
1 parent 346dcb3 commit 4a1937c
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions Storage/Storage/LCUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public Task DisassociateWithAuthData(string platform) {
if (string.IsNullOrEmpty(platform)) {
throw new ArgumentNullException(nameof(platform));
}
return LinkWithAuthData(platform, null);
return UnlinkWithAuthData(platform);
}

/// <summary>
Expand Down Expand Up @@ -523,11 +523,34 @@ public static LCQuery<LCUser> GetQuery() {
return new LCQuery<LCUser>(CLASS_NAME);
}

Task LinkWithAuthData(string authType, Dictionary<string, object> data) {
async Task LinkWithAuthData(string authType, Dictionary<string, object> data) {
Dictionary<string, object> oriAuthData = new Dictionary<string, object>(AuthData);
AuthData = new Dictionary<string, object> {
{ 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<string, object> oriAuthData = new Dictionary<string, object>(AuthData);
AuthData = new Dictionary<string, object> {
{ authType, null }
};
try {
await Save();
oriAuthData.Remove(authType);
AuthData = oriAuthData;
} catch (Exception e) {
AuthData = oriAuthData;
throw e;
}
}

static async Task<LCUser> Login(Dictionary<string, object> data) {
Expand Down

0 comments on commit 4a1937c

Please sign in to comment.