If my user click to "forgot password", and email with a one-time login is sended.

When the user clicks the given link, he's redirected to this page /user/reset/$id with the user_pass_reset form (basically containing a single button for the one-time login)

I'd like to redirect to a custom page after the user clicked on the one-time login button, but can't find out why this code doesn't works

 * Implements hook_form_BASE_FORM_ID_alter().
function module_form_user_pass_reset_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
  $form['actions']['submit']['#submit'][] = '_module_user_reset_pass_form_submit';

function _module_user_reset_pass_form_submit(&$form, FormStateInterface $form_state) {

I'm using drupal 9


1 Answer 1


Look at the code of the Login Destination module. But maybe the Password Reset Landing Page module is actually what you are looking for.

Because you normally also need to take care of having the users reset their passwords after accessing a one-time login link.

Users often forget to change their password after they use the one time login link in their password reset email. Forgetting to set their password will require them to request password reset link emails repeatedly, without fixing the underlying problem - namely that they haven't set their password to something they can remember.

The Password Reset Landing Page "PRLP" module enhances the original password reset landing page by letting a user set their new password at the same time they "log in" using the one-time-login link. It can also show a username and email address field. The password entry field can be configured to be mandatory. Other entry fields can be hidden through configuration and the page the user is taken to after login can be configured.

Also look at the Similar modules section of PRLP.

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.