# Error triying to login users using aspnet core api

**URL:** <https://community.auth0.com/t/error-triying-to-login-users-using-aspnet-core-api/138690>\
**Category:** Get Help\
**Tags:** users, management-api\
**Created:** [July 11, 2024, 10:52pm UTC](https://community.auth0.com/t/error-triying-to-login-users-using-aspnet-core-api/138690 "2024-07-11T22:52:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yarlen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yarlen/32/58503_2.png) [@yarlen](https://community.auth0.com/u/yarlen)\
**Post date:** [July 11, 2024, 10:52pm UTC](https://community.auth0.com/t/error-triying-to-login-users-using-aspnet-core-api/138690/1 "2024-07-11T22:52:47Z")

</div>

I am triying to log in users using [asp.net](http://asp.net) core api, and I am getting this error:

```auto
{"error":"access_denied","error_description":"Cannot read property 'AuthRoles' of undefined"}

```

I am triying to login the user this way:

try  
{  
// Obtain access token for Auth0 Management API  
var accessToken = await GetAuth0ApiAccessTokenAsync();

```
 // Initialize Auth0 Management API client
 var managementApiClient = new ManagementApiClient(accessToken, auth0Options.Domain);

 // Create user request
 var userCreateRequest = new UserCreateRequest
 {
     Email = user.Email,
     Password = user.Password,
     Connection = auth0Options.Connection,
     VerifyEmail = false,
     UserMetadata = new Dictionary<string, string>()
 {
     { "given_name", user.FirstName },
     { "family_name", user.LastName },
     { "phone_number", user.PhoneNumber },
 }
 };

 // Create user on Auth0
 var newUser = await managementApiClient.Users.CreateAsync(userCreateRequest);
 
 // Return the created user's ID
 return newUser.UserId;

```

}  
catch (Exception ex)  
{  
// Handle exceptions and log errors  
[//Log.Error](https://Log.Error)(“An unexpected error occurred while creating user on Auth0: {userEmail}. Exception message: {ExceptionMessage}”, user.Email, ex.Message);  
throw new Exception("An unexpected error occurred: " + ex.Message, ex);  
}

---

<div class="post-metadata">

**Author:** ![gparascandolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gparascandolo/32/38788_2.png) [@gparascandolo](https://community.auth0.com/u/gparascandolo)\
**Post date:** [July 12, 2024, 5:56pm UTC](https://community.auth0.com/t/error-triying-to-login-users-using-aspnet-core-api/138690/2 "2024-07-12T17:56:31Z")

</div>

Hey @yarlen 👋

Do you have some Auth0 Action or Auth0 Rule that is attempting to look for this ‘AuthRoles’ property that doesn’t exist yet for the account you are creating? I believe the error may be caused because of this

---

<div class="post-metadata">

**Author:** ![yarlen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yarlen/32/58503_2.png) [@yarlen](https://community.auth0.com/u/yarlen)\
**Post date:** [July 14, 2024, 12:33pm UTC](https://community.auth0.com/t/error-triying-to-login-users-using-aspnet-core-api/138690/3 "2024-07-14T12:33:56Z")

</div>

Yeah, thx, I just deleted and old unused Auth0 Action, and then works pretty well. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 28, 2024, 12:34pm UTC](https://community.auth0.com/t/error-triying-to-login-users-using-aspnet-core-api/138690/4 "2024-07-28T12:34:28Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
