Skip to main content

How to assign a role automatically when creating a user?

We may need to assign a role automatically to users who register on a Drupal site. This avoids having to do it in the admin if the account needs to be validated and it allows users to have the right role if the account is activated automatically.

Assign a role automatically when creating a user

We can do it with hook but there is a module that does it very simply: Registration role

This module allows to assign a role when the user registers on a site via the form /user/register

The module offers an option that allows not to assign the role if the user is created from the back office. This is practical because it allows you to create admins, for example, who will not have the role of users who register in front.

Other useful resources

Add new comment

Similar blog posts

How to delete local changes with git that you haven't committed ?