Fix/handle htmx requests for private page on session expiry#4531
Merged
Conversation
frjo
approved these changes
May 5, 2025
wes-otf
approved these changes
May 5, 2025
Contributor
|
great fix! worked really well |
When a user's session expires and they click on a submission in the dashboard, the login page is rendered within the submissions section of the page (via HTMX swap) instead of redirecting to the login page. This creates a broken user experience as shown in the screenshot in the issue. Created a new middleware `HtmxAuthMiddleware` that: 1. Intercepts HTMX requests that would normally redirect to the login page 2. Instead of allowing HTMX to swap the login page content, it issues a client-side redirect to the login page 3. Preserves the original path in the 'next' parameter so the user returns to the right page after login Tested by running unit tests on the middleware that verify: 1. HTMX requests that get redirected to login are properly converted to client-side redirects 2. Non-HTMX requests are not affected 3. HTMX requests with non-auth redirects are not affected Fixes #4530
5c18e77 to
03cfa62
Compare
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a user's session expires and they click on a submission in the
dashboard, the login page is rendered within the submissions section of
the page (via HTMX swap) instead of redirecting to the login page. This
creates a broken user experience as shown in the screenshot in the
issue.
Created a new middleware
HtmxAuthMiddlewarethat:page
client-side redirect to the login page
returns to the right page after login
Tested by running unit tests on the middleware that verify:
client-side redirects
Fixes #4530