I have a registration form, when submitted, the user gets logged in automatically.
I want to redirect the users to a specific page on login. Whether they are logged in using the login form or through the registration form.
I used the following code first,
function yourmodule_user_login($account) { // We want to redirect user on login. $response = new RedirectResponse("yourpath"); $response->send(); return; }
This is not working because it’s called before submit handlers so this would prevent them from being called.
Then I added a custom submit handler to the login form and redirect the users in that submit handler.
$form_state->setRedirect('mymodule.mypage');
This works fine only when the user logged in using the login form but not working for the registration form. When I use a custom submit handler for the registration and redirect the user there, I think at that time the user is not logged when the redirection occure.
Is there any other method to redirect the users on login through code?