I'm looking to redirect or prevent access for authenticated users to the /user
page. The reason being that it serves no purpose being there so would like to either remove or redirect it.
The best I've managed so far is to redirect the user on login so they don't get dropped on the /user
page straight after logging in which works great but I'd like to prevent all access to it. The code I've used for the redirect is below:
function mymodule_user_login($account) {
// Redirect users on login
$link = Link::createFromRoute(
"Admin",
"admin.home"
)->getUrl()->toString();
$homeResponse = new RedirectResponse("{$link}");
$homeResponse->send();
return;
}
Just a note for anyone potentially using the above code - it only works in a .module file, not a .theme file which took me a while to work out.