redirecting from hook_user_login()

Created on 26 September 2018, almost 6 years ago
Updated 31 January 2023, over 1 year ago

In Drupal 7 from the hook_user_login() you were able to change the $edit['redirect'] and cause the user to be redirected after login to the user would get redirected to the page, However this ability was lost during the Drupal 8 rewrite.

I was using the redirect after login which leveraged hook_user_login() and just printed the RedirectResponse() to redirect the user. I had to do some changes to that module to make it work with an ajax login, and added an exit() so we would not cause any problems.

My client is also using the Janrain module for SSO, and if I just exit() hook_janrain_capture_user_authenticated() doesn't get called when users login.

I am going to try removing the exit() from hook_user_login() and see how this acts, but I am not 100% sure =what side effects will this have.

What I asking is, is there a better method to do this, a Drupal 8 way or will there need to be some changes like changing hook_user_login() to return an Url() object and this is what you will redirect to.

Feature request
Status

Needs work

Version

10.1

Component
User module 

Last updated 1 day ago

Created by

🇦🇺Australia gordon Melbourne

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024