Search code examples
c#asp.net-identityasp.net-core-webapiasp.net-core-3.1

Is calling UserManager.IsEmailConfirmedAsync() always required?


I've seen many code samples with the following sequence:

var user = await userManager.FindByNameAsync(userName);
bool emailConfirmed = userManager.IsEmailConfirmedAsync(user);

I'm wondering why the 2nd call is necessary. In my tests, user.EmailConfirmed property is always set properly after the 1st call.

Are there possible cases where the property will not be set properly by the 1st call?


Solution

  • In your case, the function call is not necessary because the data is stored in your database and is returned by the FindBy... call, as you have pointed out.

    The purpose of the function is for a custom UserManager implementation that may need to query an external system (such as an email validation micro-service) to determine whether the email address has been validated. The function is really more of a placeholder in the UserManager interface for other solutions that may implement additional functionality - or for unit testing with a mock.

    There's no reason that you have to make that call in your case.