I want to assign a role to a user after the user confirms his/her email.

How do I do this?

  • Please mention your Drupal version (6 or 7 ?)
    – AKS
    Oct 23, 2012 at 18:43

2 Answers 2


You'll want to take a look at Rules and LoginToboggan (as per this answer on Drupal Answers).

Rules will allow you to add a "trigger", such as adding a role to a user, and LoginToboggan will provide the "trigger" for when the account is validated.


You can use hook_user_login(&$edit, $account) which is called from user_login_finalize().

When $edit parameter is empty is because is called from user_pass_reset() menu callback:

// user_login_finalize() also updates the login timestamp of the
// user, which invalidates further use of the one-time login link.

This example should work:

function MYMODULE_user_login(&$edit, $account) {
  if (empty($edit)) {
    // @todo Add role to $account->roles array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.