You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using server actions in my Next.js app (export function myAction() {} with use server). These server actions are invoked from client components.
I want to include a custom request header (e.g., X-Custom-Header) in every request made from the client to these server actions. The goal is for this header to be accessible in my middleware.ts, where I can process it further.
Is there a standard or recommended way to achieve this without globally overriding fetch? Ideally, I’d like to ensure that all server action calls automatically include this header without requiring modifications to every individual action invocation, but it's still okay if there are ways to achieve this with modifications to the function itself.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
I'm using server actions in my Next.js app (export function myAction() {} with use server). These server actions are invoked from client components.
I want to include a custom request header (e.g., X-Custom-Header) in every request made from the client to these server actions. The goal is for this header to be accessible in my middleware.ts, where I can process it further.
Is there a standard or recommended way to achieve this without globally overriding fetch? Ideally, I’d like to ensure that all server action calls automatically include this header without requiring modifications to every individual action invocation, but it's still okay if there are ways to achieve this with modifications to the function itself.
Thanks!
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions