Skip to content

Add configureClient() to intercept framework fetch requests - #112

Open
JoviDeCroock wants to merge 3 commits into
mainfrom
claude/investigate-auth-header-loaders-JYfVh
Open

Add configureClient() to intercept framework fetch requests#112
JoviDeCroock wants to merge 3 commits into
mainfrom
claude/investigate-auth-header-loaders-JYfVh

Conversation

@JoviDeCroock

Copy link
Copy Markdown
Owner

Summary

Add configureClient({ fetch }) API that allows apps to install a custom fetch implementation for all framework-initiated client requests. This enables forwarding auth headers (e.g. Authorization: Bearer …) to loaders on client-side navigations, revalidations, prefetches, and <Form> submissions without losing them after initial SSR.

The custom fetch is routed through:

  • Route-state fetches during navigation/revalidation/prefetch
  • <Form> submissions

This is particularly useful for bearer token-based auth where the token is stored on the client and must be attached to every request, unlike session cookies which flow automatically.

Testing

  • Added comprehensive test suite (configure-client.test.ts) covering:
    • Custom fetch routing for fetchPrachtRouteState
    • Fallback to global fetch when unconfigured
    • Reset to global fetch when fetch: undefined is passed
    • Header forwarding from custom fetch implementations
    • <Form> submission routing through custom fetch
  • pnpm test passes

Checklist

  • Docs updated (DATA_LOADING.md with header forwarding guide, auth recipe with bearer token example)
  • Changeset added
  • Exports added to index.ts (configureClient, ConfigureClientOptions, PrachtClientFetch)

https://claude.ai/code/session_0159U8Fz9HjrYH6iFYfJYFpT

@JoviDeCroock
JoviDeCroock force-pushed the claude/investigate-auth-header-loaders-JYfVh branch 2 times, most recently from 2856ba3 to 906a2bb Compare April 18, 2026 08:41
@JoviDeCroock
JoviDeCroock force-pushed the claude/investigate-auth-header-loaders-JYfVh branch 5 times, most recently from f1d5c94 to 09b2b07 Compare July 7, 2026 17:16
Introduces configureClient({ fetch }) so apps can install a custom fetch
used by every framework-initiated client request: route-state fetches on
navigation, useRevalidate, prefetch, and <Form> submissions. Enables
forwarding an Authorization header (e.g. a bearer token held on the
client) so server-side loaders can read it from request.headers on both
the initial SSR request and every subsequent client-triggered fetch.
@JoviDeCroock
JoviDeCroock force-pushed the claude/investigate-auth-header-loaders-JYfVh branch from 09b2b07 to c497d16 Compare July 9, 2026 05:26
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.

2 participants