Problem/Motivation
The JS always make requests to the routes even if user is not logged. This results in several requests returning 403 and being unneeded.
Proposed resolution
function autologout_attach_js(array &$element, array $settings) {
if (\Drupal::currentUser()->isAuthenticated()){
$element['#attached']['drupalSettings']['autologout'] = $settings;
$element['#attached']['library'][] = 'autologout/drupal.autologout';
$element['#cache']['tags'][] = 'config:autologout.settings';
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | autologout-anonymous-user.png | 23.03 KB | inregards2pluto |
| #15 | autologout-authenticated-user.png | 31.23 KB | inregards2pluto |
| #11 | Screenshot from 2025-04-02 17-03-13.png | 89.66 KB | uttam |
| #11 | Screenshot from 2025-04-02 17-03-29.png | 95.83 KB | uttam |
| #8 | authenticated_user.png | 45.68 KB | anish.ir |
Issue fork autologout-3498529
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
sandip commentedWorking on it.
Comment #3
sandip commentedHi @emanuelcoelho,
I think we can check the authenticated user condition in
function autologout_page_attachments_alter(array &$attachments)from wherefunction autologout_attach_js(array &$element, array $settings)is called.If you agree i will start working on it.
Comment #4
emanuelcoelho commentedHi sandip,
Yes if possible.
Comment #6
sandip commentedPlease review the MR
Comment #7
emanuelcoelho commentedEverything looks perfect.
For me it's a go.
Thank you for the quick response.
Comment #8
anish.ir commentedHey @emanuelcoelho,
I have tried reproducing your issue but the libraries mentioned above are not being attached for anonymous users and is only being attached for authenticated users. So, I don't think we will need any validation here. I think the validation is already present for anonymous users.
The above validation present in the
autologout_autologout_prevent()method is validating for anonymous users.Please provide detailed steps to replicate the issue, if I am missing something here.
I am using Drupal 11 and 2.x-dev version of the Module here. I am attaching screenshots for the reference.
Thanks !
Comment #9
anish.ir commentedComment #10
uttam commentedI have tested the module, and I observed that the autologout.js file is not loading for anonymous users but is correctly loading for authenticated users. This behavior occurs without applying the proposed patch.
Since the reported issue was about autologout.js making unnecessary requests for anonymous users, but that is not happening in the 2.x-dev version, this might already be resolved.
Can anyone confirm if this issue still exists in any specific scenario?
Moving the issue to NR for now.
Comment #11
uttam commentedComment #12
divyansh.gupta commentedMarking this as RTBC. The MR ensures that the JS file is only attached for authenticated users, as expected. It’s a straightforward change and has already been confirmed to work correctly by others. Looks good to go.
Comment #13
the_g_bomb commentedAgreed and confirmed. This appears to be a low-risk and straightforward change. It has a performance benefit and seems to work well.
Comment #15
inregards2plutoRe-tested post https://www.drupal.org/project/autologout/issues/3339695 merge and can confirm behavior is still as expected. Not sure if due to other upstream changes in 2.x or due to patch, but it sounds like maintainers feel that its a low risk and straightforward change, so I'll trust the maintainer powers that be :)
Comment #17
the_g_bomb commentedMerged