Base solution for your next web application
Open Closed

"Email '[email protected]' is already taken" Error on Login After 4.x to 8.4 Upgrade #8751


User avatar
0
wizgod created

Greetings Programs!

I have been working on migrating a 4.x MVC application to an 8.4 Angular + Core application.

I have LDAP enabled with multi-tenancy and I moved all the users over along with their roles (accounting for column changes).

When I try to log in using credentials ( testing with two users), I receive the "Email 'myemail' is already taken" error. It seems like it couldn't find the user and is trying to add the user instead of logging in.

The log in production doesn't seem to be showing the error but in dev, I get the output below.

Thanks,

Wg

Mvc.ExceptionHandling.AbpExceptionFilter - Email '[email protected]' is already taken.
Abp.UI.UserFriendlyException: Email '[email protected]' is already taken.
   at Abp.Authorization.Users.AbpUserManager`2.CheckDuplicateUsernameOrEmailAddressAsync(Nullable`1 expectedUserId, String userName, String emailAddress)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Authorization.Users.AbpUserManager`2.CreateAsync(TUser user)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Authorization.AbpLogInManager`3.TryLoginFromExternalAuthenticationSourcesAsync(String userNameOrEmailAddress, String plainPassword, TTenant tenant)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Authorization.AbpLogInManager`3.LoginAsyncInternal(String userNameOrEmailAddress, String plainPassword, String tenancyName, Boolean shouldLockout)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at Abp.Authorization.AbpLogInManager`3.LoginAsync(String userNameOrEmailAddress, String plainPassword, String tenancyName, Boolean shouldLockout)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.InternalInterceptAsynchronous[TResult](IInvocation invocation)
   at MyAppInc.Web.Controllers.TokenAuthController.GetLoginResultAsync(String usernameOrEmailAddress, String password, String tenancyName) in C:\Projects\Core + Angular - 8.4\MyAppInc\aspnet-core\src\MyAppInc.Web.Core\Controllers\TokenAuthController.cs:line 652
   at MyAppInc.Web.Controllers.TokenAuthController.Authenticate(AuthenticateModel model) in C:\Projects\Core + Angular - 8.4\MyAppInc\aspnet-core\src\MyAppInc.Web.Core\Controllers\TokenAuthController.cs:line 138
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeNextActionFilterAsync&gt;g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.&lt;InvokeInnerFilterAsync&gt;g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.&lt;InvokeNextExceptionFilterAsync&gt;g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

11 Answer(s)
  • User Avatar
    0
    wizgod created

    I found that I was able to log in with the email address and after that, I was able to log in normally with the username.

    Is there something I can update so this isn't necessary?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @wizgod

    What is your ABP Nuget package version ?

  • User Avatar
    0
    wizgod created

    Hi @ismcagdas,

    Abp and Abp.* packages are v5.4.0 with Abp.AspNetZeroCore and Abp.AspNetZeroCore.Web being v2.0.0.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This happens here. There is a class named LoginManager.cs in your project. You can override it's TryLoginFromExternalAuthenticationSourcesAsync method and copy the same code from link above I have shared. Then, you can debug and see what causes the problem.

  • User Avatar
    0
    wizgod created

    Hi @ismcagdas,

    I added that code and overrode the method in LogInManager.

    At:

    var user = await UserManager.FindByNameOrEmailAsync(tenantId, userNameOrEmailAddress);

    • It can't find the user when userNameOrEmailAddress is the username; the value returns null (the correct tenantId is passed).
    • It does find the user if the email address is used.
    • If I switch back to loging in with the username after using the email address, it finds the user.

    When it's null,it trys to create the object and the "Email is already taken" exception is thrown at:

    await UserManager.CreateAsync(user);

  • User Avatar
    0
    ismcagdas created
    Support Team
  • User Avatar
    0
    wizgod created

    Hi @ismcagdas,

    Will do. I'll let you know in about 10 days; tied up till then.

    Thanks,

    Wg

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks :)

  • User Avatar
    0
    wizgod created

    Hi @ismcagdas,

    Has that method changed for 8.5.0?

    It's saying that _passwordHasher is not accessable because it's private.

    Thanks,

    Wg

  • User Avatar
    0
    wizgod created

    @ismcagdas, I've figured it out; it was an oversight on my part.

    When I was migrating the users, I was setting the new NormalizedUserName column with UPPER(Name + ' ' + Surname) instead of UPPER(UserName).

    Thanks,

    Wg

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @wizgod :)