TanStackT
TanStack6mo ago
6 replies
sacred-rose

How to check if a server function has a certain middleware

Say i have a middleware
export const requireAuthMiddleware = createMiddleware({
  type: "function",
}).server(async ({ next }) => {...});

and i have some server function
export const serverGetUser = createServerFn({
  method: "GET",
})
  .middleware([ ??? ])
  .handler(async ({ context }) => { ... });

how can i check if the sfn "serverGetUser" has the "requireAuthMiddleware" middleware? i need it so that i can implement a generic check for a folder where i'll put all my protected server fns

if there's no way to check this, then is there a way to make wrappers/factories for the createServerFn? I've tried but as far as i understand its not possible at the moment because the compiler is designed to statically analyze createServerFn calls
Was this page helpful?