Skip to content

Fix/handle htmx requests for private page on session expiry#4531

Merged
frjo merged 2 commits into
mainfrom
fix-htmx-auth-redirect
May 6, 2025
Merged

Fix/handle htmx requests for private page on session expiry#4531
frjo merged 2 commits into
mainfrom
fix-htmx-auth-redirect

Conversation

@theskumar

Copy link
Copy Markdown
Member

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

@theskumar theskumar self-assigned this May 3, 2025
@theskumar theskumar changed the title Fix/handle htmx requests for private page after session expires Fix/handle htmx requests for private page on session expiry May 3, 2025
@frjo frjo added Type: Bug Bugs! Things that are broken :-/ Type: Patch Mini change, used in release drafter Status: Needs testing Tickets that need testing/qa Status: Needs dev testing 🧑‍💻 Tasks that should be tested by the dev team labels May 5, 2025
@wes-otf wes-otf added Status: Tested - approved for live ✅ and removed Status: Needs testing Tickets that need testing/qa Status: Needs dev testing 🧑‍💻 Tasks that should be tested by the dev team labels May 5, 2025
@wes-otf

wes-otf commented May 5, 2025

Copy link
Copy Markdown
Contributor

great fix! worked really well

theskumar added 2 commits May 6, 2025 08:10
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
@frjo frjo force-pushed the fix-htmx-auth-redirect branch from 5c18e77 to 03cfa62 Compare May 6, 2025 06:11
@frjo frjo merged commit 6131f9a into main May 6, 2025
7 checks passed
@sentry

sentry Bot commented May 15, 2025

Copy link
Copy Markdown

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ SystemExit: 1 /apply/submissions/{pk}/comments/ View Issue
  • ‼️ SystemExit: 1 /apply/submissions/{submission_pk}/determinatio... View Issue
  • ‼️ SystemExit: 1 /apply/submissions/{pk}/lead/update/ View Issue

Did you find this useful? React with a 👍 or 👎

@theskumar theskumar deleted the fix-htmx-auth-redirect branch July 20, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Tested - approved for live ✅ Type: Bug Bugs! Things that are broken :-/ Type: Patch Mini change, used in release drafter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Login page is rendered in htmx request section

3 participants