TanStackT
TanStack7mo ago
2 replies
popular-magenta

Returning in middleware

Hi, I'm just getting started with TanStack Start. Right now I'm trying to do something like:

export const authMiddleware = createMiddleware({ type: 'function' }).server(async ({ next }) => {
  const h = getHeaders();

  if (h['x-auth'] !== 'good') {
    setResponseStatus(403);
    return json({ error: 'Forbidden' });
  }

  return next();
});


but this gives a type error and doesn't seem to work.

How do I return in a middleware? Or should I be using something else for this?
Was this page helpful?