I am using Amazon.AspNetCore.Identity.Cognito and while using "ConfirmEmailAsync(TUser user, string token)" of UserManager, I am getting the NullReferenceException.
The Screenshot is provided:
The Code I did:
[HttpPost]
[ActionName("Confirm")]
public async Task<IActionResult> Confirm_Post(ConfirmModel model)
{
if(ModelState.IsValid)
{
var user = await _userManager.FindByEmailAsync(model.Email);
if(user == null)
{
ModelState.AddModelError("NotFound", "A user with given email address was not found");
}
var result = await _userManager.ConfirmEmailAsync(user, model.Code).ConfigureAwait(false);
if(result.Succeeded)
{
return RedirectToAction("Index", "Home");
}
else
{
foreach(var item in result.Errors)
{
ModelState.AddModelError(item.Code, item.Description);
}
}
}
}
Please tell me how to solve this, as I am new to AWS, it seems puzzling.
Okay I get a solution, now it no more causes the exception. I use ConfirmSignUpAsync(TUser user, string confirmationCode, bool forcedAliasCreation) method instead of ConfirmEmailAsync(TUser user, string token) and it works!!
var result = await ((CognitoUserManager<CognitoUser>)_userManager).ConfirmSignUpAsync(user, model.Code, true);
if(result.Succeeded)
{
return RedirectToAction("Index", "Home");
}
The code is shared below, and if anyone finds it helpful, it'd be a pleasure. Thanks all!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.