TanStackT
TanStack5w ago
5 replies
then-purple

Server Functions with method: "POST" still use GET requests

When creating a reusable server function helper with middleware like this:
// src/lib/middlewares/index.ts
const adminMiddleware = createMiddleware()
  .server(async ({ next, context }) => {
    // auth logic...
    return next({ context });
  });
export const createAdminFn = createServerFn().middleware([adminMiddleware]);

And then trying to specify the method when using it:
// src/features/posts/api/posts.admin.api.ts
export const updatePostFn = createAdminFn({
  method: "POST",  //  This option is IGNORED
})
  .inputValidator(...)
  .handler(async ({ data, context }) => {
    // ...
  });

Check the Network tab - it sends a GET request with extremely long URL.
Was this page helpful?