Skip to content

[#197][#201] fix: centralize Bearer auth across non-/api requests - #199

Merged
sksingh2005 merged 1 commit into
mnemosyne-systems:mainfrom
Mohamed-Alkafory:fix/report-export-auth
Sep 25, 2026
Merged

sksingh2005 merged 1 commit into
mnemosyne-systems:mainfrom
Mohamed-Alkafory:fix/report-export-auth

Conversation

@Mohamed-Alkafory

@Mohamed-Alkafory Mohamed-Alkafory commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #197, Closes #201

What this does

After the Keycloak migration, requests outside /api/* weren't carrying the auth token (backend no longer reads cookies). This affected report export, form POSTs (Add User, Create Ticket, etc.), and read hooks (useJson/useText, e.g. the ticket alarm status poll).

Approach (per review feedback)

Instead of patching each call site separately, centralized the fix: AuthProvider's existing fetch interceptor now covers all same-origin requests (previously /api/* only), not just a widened set of individual helpers. This eliminated duplicate token-refresh logic and let me delete the per-file workarounds entirely — api.ts, useJson, and useText are now back to plain fetch calls with no special auth wiring of their own.

Also removed the BACKEND_ORIGIN cross-origin logic in ReportsPage.tsx (unnecessary — dev runs through Quarkus Quinoa on :8080, so :5173 is never hit directly) in favor of a relative path, consistent with the rest of the frontend.

@sksingh2005

Copy link
Copy Markdown
Collaborator

@Mohamed-Alkafory Thanks for working on this! Few suggestions:

@Mohamed-Alkafory Mohamed-Alkafory changed the title [#197] fix: report export auth [#197][#201] fix: centralize Bearer auth across non-/api requests Sep 24, 2026
@jesperpedersen

Copy link
Copy Markdown
Contributor

@Mohamed-Alkafory Remember to squash

@Mohamed-Alkafory

Copy link
Copy Markdown
Contributor Author

@jesperpedersen Thanks for the reminder — done, squashed into a single commit.

@Mohamed-Alkafory

Copy link
Copy Markdown
Contributor Author

@sksingh2005 Thanks for the detailed review! Addressed all points:

  • History squashed into a single commit — linear now, merge commit gone
  • Removed BACKEND_ORIGIN, using relative paths
  • Centralized auth in AuthProvider's fetch interceptor instead of per-file
    workarounds — deleted withAuthHeader entirely, api.ts/useJson/useText are
    back to plain fetch

PTAL whenever you get a chance!

@sksingh2005 sksingh2005 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Two non-fetch paths still bypass auth: utils/forms.ts:66 (submitBrowserForm, fallback in CompanyFormPage.tsx:277 will 403) and ticket PDF anchors in SupportTicketDetailPage.tsx:1341,1359 (plain href GETs carry no Bearer). Worth a follow-up.

[mnemosyne-systems#201] fix: attach auth token to form POST requests

Attach Bearer token to read-hook requests (useJson/useText)

[mnemosyne-systems#197][mnemosyne-systems#201] fix: centralize Bearer auth in AuthProvider fetch interceptor

Widen the global fetch patch from /api/* to all same-origin paths so
form POSTs, report exports, and alarm/read hooks share one token path.
Drop the per-caller withAuthHeader helper (api.ts, useJson, useText)
and the manual refresh in ReportsPage export, and use relative export
paths (Quinoa serves dev on :8080, so :5173 cross-origin is dead code).
@Mohamed-Alkafory

Copy link
Copy Markdown
Contributor Author

@sksingh2005 Addressed both:

  1. Removed the submitBrowserForm fallback in CompanyFormPage — it was
    firing an unauthenticated POST after the Keycloak migration removed
    cookie auth. Now surfaces a network error instead.
  2. Replaced the two plain PDF export links in
    SupportTicketDetailPage with authenticated fetch + blob download,
    mirroring the existing ReportsPage.exportReport pattern.

PTAL!

@sksingh2005

Copy link
Copy Markdown
Collaborator

@Mohamed-Alkafory Please rebase

@Mohamed-Alkafory

Copy link
Copy Markdown
Contributor Author

@sksingh2005 Double-checked on my end — the branch is already rebased
on latest main (git log fix/report-export-auth..origin/main is empty),
the last force-push (84870be) came after that rebase, and GitHub shows
"No conflicts with base branch" with all checks passing. Let me know if
you meant something else!

@sksingh2005
sksingh2005 merged commit 3931fe8 into mnemosyne-systems:main Sep 25, 2026
2 checks passed
@sksingh2005

Copy link
Copy Markdown
Collaborator

Merged. Thanks for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-/api requests missing auth token after Keycloak migration Report export fails with 401/404 (auth token not sent)

3 participants