I'm having issues with the SetEmailConfirmedAsync method within my UserStore class.
Everything is working fine, users are being created with hashed password, tokens are being generated for the confirmation email, the email is sending successfully. The problem comes when I try to verify the email
public async Task<ActionResult> ConfirmEmail(Guid userId, string token)
{
Task<Microsoft.AspNet.Identity.IdentityResult> result = UserManager.ConfirmEmailAsync(userId, token);
if (result.Result.Succeeded)
{
}
else
{
}
return View();
}
This then calls
public Task SetEmailConfirmedAsync(User user, bool confirmed)
{
AccountService.VerifiyAccount(user.Id, confirmed);
return Task.FromResult(0);
}
which sets the account to verified as i'd expect. However, the next thing that happens is that the FindByNameAsync is called followed by the UpdateAsync method which overwirtes my changes applied within SetEmailConfirmedAsync.
Does anyone know why asp.net Identity makes a call to UpdateAsync after SetEmailConfirmedAsync? I've searched around for some clues but cant find anything.
Update
I've done some digging and pulled this from the Identity source code
public virtual async Task<IdentityResult> ConfirmEmailAsync(TKey userId, string token)
{
ThrowIfDisposed();
var store = GetEmailStore();
var user = await FindByIdAsync(userId).WithCurrentCulture();
if (user == null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.UserIdNotFound,
userId));
}
if (!await VerifyUserTokenAsync(userId, "Confirmation", token).WithCurrentCulture())
{
return IdentityResult.Failed(Resources.InvalidToken);
}
await store.SetEmailConfirmedAsync(user, true).WithCurrentCulture();
return await UpdateAsync(user).WithCurrentCulture();
}
I'm struggling to figure out why a call to update user would be made after SetEmailConfirmedAsync has been called