private async Task <IActionResult> HandleMerge(IdentityUser user, string returnUrl) { var currentUser = await _userManager.GetUserAsync(User); if (user == null || currentUser == null) { StatusMessage = "An error occured."; return(RedirectToPage("Merge")); } if (user.Id == currentUser.Id) { StatusMessage = "That login is already associated with this account!"; return(RedirectToPage("Merge")); } await _mergeService.MergeUsers(currentUser, user); // delete temporary cookie used during external authentication await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); var updatedUser = await _userManager.GetUserAsync(User); await _signInManager.SignInAsync(updatedUser, isPersistent : false); return(ReturnToUrl(returnUrl)); }