Skip to content

fix(auth): redirect unauthorized page requests - #628

Open
JustinShetty wants to merge 3 commits into
C4illin:mainfrom
JustinShetty:fix/auth-page-redirect
Open

fix(auth): redirect unauthorized page requests#628
JustinShetty wants to merge 3 commits into
C4illin:mainfrom
JustinShetty:fix/auth-page-redirect

Conversation

@JustinShetty

@JustinShetty JustinShetty commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Instead of printing the 401 error's JSON when accessing an unauthorized page (e.g. /results/21 without an active session)

image

This updates the auth handler to distinguish between page navigation (HTML request) and API requests.

  • Unauthorized API requests get a 401 error.
  • Unauthorizedpage naviation gets a 302 redirect back to /login

This PR also adds a test to cover the API vs page navigation logic.


Summary by cubic

Redirects unauthorized page navigation to /login instead of showing the 401 JSON error, while API requests still get 401 responses.

  • Adds an isHtmlPageRequest helper that detects HTML navigation via GET/HEAD requests whose accept header includes text/html (case-insensitive).
  • Clears an invalid session cookie before redirecting.
  • Adds tests covering page navigation and API request detection.

Written for commit bbd2f21. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added the Fix label Sep 1, 2026
@JustinShetty

Copy link
Copy Markdown
Contributor Author

Happy to hear out other approaches here, this just felt like the minimal change required to improve the typical user's experience

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/pages/auth.test.ts
Comment thread src/helpers/isHtmlPageRequest.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant