diff --git a/RavenDB.Identity/RavenDB.Identity.csproj b/RavenDB.Identity/RavenDB.Identity.csproj
index d7b1597..efb6e5d 100644
--- a/RavenDB.Identity/RavenDB.Identity.csproj
+++ b/RavenDB.Identity/RavenDB.Identity.csproj
@@ -19,10 +19,10 @@
false
false
false
- 6.0.1
+ 6.0.2
False
Raven.Identity
- Compare/exchange to enforce unique emails cluster-wide, storing with email address as the key.
+ Fixed user deletion that failed to delete compare/exchange key.
diff --git a/RavenDB.Identity/UserStore.cs b/RavenDB.Identity/UserStore.cs
index cafd231..404656b 100644
--- a/RavenDB.Identity/UserStore.cs
+++ b/RavenDB.Identity/UserStore.cs
@@ -192,11 +192,6 @@ namespace Raven.Identity
ThrowIfNullDisposedCancelled(user, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
- // Delete the user and save it. We must save it because deleting is a cluster-wide operation.
- // Only if the deletion succeeds will we remove the cluseter-wide compare/exchange key.
- this.DbSession.Delete(user);
- await this.DbSession.SaveChangesAsync();
-
// Remove the cluster-wide compare/exchange key.
var deletionResult = await DeleteUserEmailReservation(user.Email);
if (!deletionResult.Successful)
@@ -211,6 +206,11 @@ namespace Raven.Identity
});
}
+ // Delete the user and save it. We must save it because deleting is a cluster-wide operation.
+ // Only if the deletion succeeds will we remove the cluseter-wide compare/exchange key.
+ this.DbSession.Delete(user);
+ await this.DbSession.SaveChangesAsync();
+
return IdentityResult.Success;
}
@@ -874,7 +874,15 @@ namespace Raven.Identity
private Task> DeleteUserEmailReservation(string email)
{
var key = GetCompareExchangeKeyFromEmail(email);
- var deleteEmailOperation = new DeleteCompareExchangeValueOperation(key, 0);
+ var store = DbSession.Advanced.DocumentStore;
+
+ var readResult = store.Operations.Send(new GetCompareExchangeValueOperation(key));
+ if (readResult == null)
+ {
+ return Task.FromResult(new CompareExchangeResult() { Successful = false });
+ }
+
+ var deleteEmailOperation = new DeleteCompareExchangeValueOperation(key, readResult.Index);
return DbSession.Advanced.DocumentStore.Operations.SendAsync(deleteEmailOperation);
}