Before login hook
-
15-02-2021 - |
Question
Is there a Drupal 8 hook for pre-login? I would like to redirect the login information of a user on a web server by URL.
I know there is hook_user_login()
, but this one only looks called once the user is connected to the database. I would like to retrieve the step before, so the login and password information.
Solution
You can solve this by implementing hook_form_alter
, something like this;
function MY_MODULE_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_form') {
$form['#validate'][] = 'my_module_user_login_validate';
}
}
function my_module_user_login_validate(&$form, $form_state) {
//Do something...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange