Due to requirements with our reverse proxies, I had to show the user login form on a different URL. Well, no problem, I thought, I'll just copy the relevant section from user.routing.yml
and display it on a different path:
mymodule.user.login:
path: '/ls/login'
defaults:
_form: '\Drupal\user\Form\UserLoginForm'
_title: 'Log in'
requirements:
_user_is_logged_in: 'FALSE'
options:
_maintenance_access: TRUE
This works, but if an user accesses the login URL after having logged in (typically because they bookmarked the login page), they get an "Access denied" page. I can understand it – after all, there is the requirement that the user is NOT logged is. I was thinking of ways to circumvent this, but then I noticed that the original URL (still accessible if I access the server directly rather than through the proxies) does not have this problem: if I go to /usr/login
it after logging in, I get redirected to the user page, /user/{{id}}
.
I don't understand how the latter works, I looked at UserLoginForm.php
in addition to user.login.form
, but I found no clue. What is involved here?