Skip to content

Send bearer token on raw fetch calls to rag-analytics - #191

Open
collinschreyer-dev wants to merge 1 commit into
devfrom
fix/rag-analytics-auth
Open

Send bearer token on raw fetch calls to rag-analytics#191
collinschreyer-dev wants to merge 1 commit into
devfrom
fix/rag-analytics-auth

Conversation

@collinschreyer-dev

Copy link
Copy Markdown
Collaborator

What

Companion to GSA/srt-api#208, which adds token() / admin_only() to the rag-analytics routes. These must merge together — without this change those calls start returning 401.

Why the header was missing

Angular attaches the bearer token via TokenInterceptor, which only sees HttpClient traffic. Sixteen calls in the analytics and home components used raw fetch(), which bypasses the interceptor entirely and sent no Authorization header.

That is precisely why the server routes had no guard: adding one would have broken them. art-lookup was the one route called through HttpClient and the one route with a server-side guard.

Change

Adds authHeaders() in src/app/shared/services/auth-fetch.ts and applies it at each fetch() call site.

home.component.ts already did this by hand for its streaming analyze call, so this generalizes an existing local fix rather than inventing a pattern.

File Calls updated
ai-playground.component.ts 13
home.component.ts 1 (a 2nd already had it)
ai-analytics.component.ts 1
ai-pipeline.component.ts 1

The execute-pipeline upload deliberately gets no Content-Type, so the browser sets the multipart boundary for its FormData body.

Verification

  • All 17 fetch() calls to rag-analytics now carry auth; audited individually.
  • Production build (ng build --configuration=dev) succeeds; only pre-existing SASS and quill warnings.
  • tsc --noEmit reports no errors in the touched files. Remaining repo-wide errors are pre-existing missing @types/jest in spec/e2e files.
  • Diff contains no request-logic changes beyond the added header.

🤖 Generated with Claude Code

Companion to the srt-api change that adds token() and admin_only() to the
rag-analytics routes. Without this, those calls would start returning 401.

Angular attaches the bearer token through TokenInterceptor, which only sees
HttpClient traffic. Sixteen calls in the analytics and home components used raw
fetch() instead, which bypasses the interceptor and sent no Authorization
header. That is why those endpoints had no server-side guard: adding one would
have broken them. art-lookup, the single guarded route, was also the single one
called through HttpClient.

Adds authHeaders() in shared/services and applies it at each fetch call site.
home.component already did this by hand for its streaming analyze call, so this
generalizes an existing local fix rather than introducing a new pattern.

The execute-pipeline upload deliberately gets no Content-Type, so the browser
can set the multipart boundary for its FormData body.

No request logic changed beyond the added header. Verified with a production
build and a typecheck of the touched files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant