Hey wishing you a great day, i am trying to assign a role to new created users using a rule called “Set roles to a user” built by default and i edit it as follow :
function setRolesToUser(user, context, callback) {
// Roles should only be set to verified users.
if (!user.email) {
return callback(null, user, context);
}
user.app_metadata = user.app_metadata || {};
// You can add a Role based on what you want
// In this case I check domain
const addRolesToUser = function (user) {
if (
user.email
) {
return ['customer'];
}
return ['user'];
};
const roles = addRolesToUser(user);
user.app_metadata.roles = roles;
auth0.users
.updateAppMetadata(user.user_id, user.app_metadata)
.then(function () {
context.idToken['https://example.com/roles'] = user.app_metadata.roles;
callback(null, user, context);
})
.catch(function (err) {
callback(err);
});
}
i try to make some edit to it to ignore if the user is verified or not as well as assigning every new user the role “customer” but when i test it i get “ERROR: The user does not exist.” where is the issue?