Replies: 3 comments 3 replies
-
|
You might want to try giving |
Beta Was this translation helpful? Give feedback.
-
|
createIsomorphicFn does not solve the double-hop on its own — it runs the same function in both environments, but when it runs on the server it still does not have the browser's cookies. The missing piece is forwarding the incoming request headers. |
Beta Was this translation helpful? Give feedback.
-
|
Did you find something on this @mfalthaw ? I am also struggling with this, api sends cookies (access and refresh) and I have to manually parse/attach them on tan-server. my current setup: code . My current setup has a problem that parallel requests are failing with 401 since they don't have the latest cookies. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The Issue: The "Double-Hop" When using TanStack Start with a stateful backend like Laravel Sanctum, authentication works perfectly on the client because the browser automatically attaches cookies and CSRF headers. However, when moving logic into a Server Function (e.g., for beforeLoad or createServerFn()), the request originates from the Start server, not the browser.
The backend API then sees a request from a "new" client and misses the context required for stateful auth:
The Current Workaround I am currently using an Axios interceptor that uses getRequestHeaders() from @tanstack/react-start/server to manually "proxy" these values from the incoming browser request to the outgoing API request:
This feels way off. Having to manually parse cookies, xsrf token, set-cookie just doesn't seem right.
The Question Is there a more TanStack Start "native" way to handle identity propagation between the client and the server?
Beta Was this translation helpful? Give feedback.
All reactions