internal Task <IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken = default) { // get the stored user document reference var doc = UsersSet.Document(user.Id); return(_db.RunTransactionAsync(async transaction => { var snapshot = await transaction.GetSnapshotAsync(doc, cancellationToken).ConfigureAwait(false); // check if the user was deleted or updated while running the transaction if (!snapshot.Exists || snapshot.GetValue <string>("ConcurrencyStamp") != user.ConcurrencyStamp) { return IdentityResult.Failed(_errorDescriber.ConcurrencyFailure()); } // delete the user logins var loginSnapshots = await UserLogins.WhereEqualTo("UserId", user.Id).GetSnapshotAsync(cancellationToken).ConfigureAwait(false); if (loginSnapshots.Count > 0) { foreach (var login in loginSnapshots) { transaction.Delete(login.Reference); } } // delete the user tokens var tokenSnapshots = await UserTokens.WhereEqualTo("UserId", user.Id).GetSnapshotAsync(cancellationToken).ConfigureAwait(false); if (tokenSnapshots.Count > 0) { foreach (var token in tokenSnapshots) { transaction.Delete(token.Reference); } } // delete the user claims transaction.Delete(UserClaims.Document(user.Id)); transaction.Delete(doc); return IdentityResult.Success; }, cancellationToken: cancellationToken)); }