start-core/middleware

Compose type-safe middleware for TanStack Start server routes and functions.

14.9k|1.8k|Updated Jan 14, 2019
One-click install
npx skills add https://github.com/TanStack/router --skill start-core-middleware
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: start-core/middleware
Source: https://github.com/TanStack/router/tree/main/packages/start-client-core/skills/start-core/middleware
Command: npx skills add https://github.com/TanStack/router --skill start-core-middleware

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Middleware in TanStack Start provides a cohesive approach to composing request processing, enabling shared context, policy enforcement, and predictable behavior across SSR, routes, and server functions.

Core Features & Use Cases

  • Request Middleware runs on all server requests (SSR, routes, functions) to log, validate, or modify requests.
  • Server Function Middleware runs on both client and server phases to enable pre/post processing and context injection.
  • Attach to Server Functions & Routes easily to enforce authentication, logging, or feature flags.
  • Context Passing uses next({ context }) to propagate data through the middleware chain to handlers.
  • Global Middleware configuration in src/start.ts for universal behavior across the app.

Quick Start

Create a middleware with createMiddleware and attach it to a server function to see contextual data flow.

Frequently Asked Questions about start-core/middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create type-safe middleware for TanStack Start server routes?

You can create type-safe middleware in TanStack Start using createMiddleware, which enforces proper method order and safe context handling. Attach the middleware to individual handlers or entire routes to apply processing logic like authentication or logging.

What is the difference between request middleware and server function middleware in TanStack Start?

Request middleware runs on all server requests including SSR and routes, while server function middleware runs on both client and server phases. Server function middleware enables pre and post processing alongside context injection for client-server interactions.

How do I pass context through a middleware chain to my server handler?

You pass context through a middleware chain by calling next with a context object: next({ context }). This propagates data through the middleware chain directly to your downstream handlers in a type-safe manner.

Can I configure global middleware for all requests in a TanStack Start application?

Yes, you can configure global middleware in the src/start.ts file. This establishes universal behavior across the entire application, ensuring consistent processing like logging or validation for all server requests and functions.

How do I enforce authentication or feature flags before a server function executes?

You enforce authentication or feature flags by attaching middleware to your server functions. The middleware processes the request, validates policies, and injects context before the main server function logic executes.

Does TanStack Start middleware support both client and server processing phases?

Yes, TanStack Start server function middleware explicitly supports both client and server phases. This allows you to run pre-processing logic on the client and continue context passing or post-processing on the server.