Setting request headers
Hi, how do I set the request headers so that I can pass an Authorization token in requests to server functions?
6 Replies
blank-aquamarine•5mo ago
I feel this is what you want
https://tanstack.com/start/latest/docs/framework/react/middleware#modifying-the-client-request
Middleware | TanStack Start React Docs
What is Server Function Middleware? Middleware allows you to customize the behavior of server functions created with createServerFn with things like shared validation, context, and much more. Middlewa...
blank-aquamarine•5mo ago
Using middleware
eastern-cyanOP•5mo ago
Perfect, thank you!
How do I register the global middleware? I have a
global-middleware.ts file but I'm not using app/ as a directory.
Ah, adding it to __root workedblank-aquamarine•5mo ago
Yeah I think it used to auto pick it up but not anymore
other-emerald•2mo ago
Sorry Im struggling in this section
How were you able to add header to the request?
stormy-gold•2mo ago
@Naseebullah (IFX) the link has changed, here is the valid link https://tanstack.com/start/latest/docs/framework/react/guide/middleware#modifying-the-client-request