Error triying to login users using aspnet core api

I am triying to log in users using asp.net core api, and I am getting this error:

{"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(“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);
}

Hey @yarlen :wave:

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

1 Like

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

1 Like

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