start-core-middleware

Implements request and server function middleware for TanStack Start applications.

Updated Dec 21, 2025
One-click install
npx skills add https://github.com/Angael/veles --skill start-core-middleware-angael
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: start-core-middleware
Source: https://github.com/Angael/veles/tree/main/.agents/skills/start-core-middleware
Command: npx skills add https://github.com/Angael/veles --skill start-core-middleware-angael

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? TanStack Start developers need a structured way to run shared logic—authentication, logging, validation, context injection—across server functions and server routes without duplicating code, while avoiding subtle security mistakes like trusting client-sent context. ## Core Features & Use Cases - Two Middleware Types: Request middleware (.server() only, runs on all server requests) and server function middleware (.client() + .server(), runs per createServerFn call). - Context Passing: Pass typed context down the chain via next({ context }) and transfer data between client and server phases with sendContext. - Global Middleware: Register app-wide request and function middleware through createStart in src/start.ts. - Middleware Factories: Build parameterized, reusable authorization middleware that composes on top of an auth middleware. - Use Case: Protect a workspace-scoped server function by validating the client-sent workspaceId shape with Zod, then verifying the session principal's membership before querying the database. ## Quick Start Show me how to create an auth middleware in TanStack Start that loads the session and attaches it to every server function.

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 middleware in TanStack Start?

Use createMiddleware() from @tanstack/react-start. Request middleware uses only .server() and runs on all server requests, while server function middleware uses createMiddleware({ type: 'function' }) with .client() and .server() phases for createServerFn calls.

What is the difference between request middleware and server function middleware?

Request middleware runs on all server requests including SSR, routes, and functions, and only supports .server(). Server function middleware runs only for createServerFn calls, supports .client() and .server() phases, and allows input validation via .validator().

How do I pass context between middleware in TanStack Start?

Return next({ context: { ... } }) from a middleware to pass typed data down the chain. Downstream middleware and handlers access it via the context argument. Use sendContext instead when transferring data between the client and server phases.

Why is validating sendContext with Zod not enough for authorization?

Zod parsing only checks the shape of client-sent data, not whether the user may access it. A valid UUID can still belong to another tenant. Always verify access against the session principal, such as a membership lookup, before using client-sent IDs in queries.

Why does localStorage crash inside TanStack Start client middleware?

During SSR, .client() callbacks execute on the server where browser APIs like localStorage and window do not exist, causing ReferenceError. Guard access with typeof window !== 'undefined' or use cookies and headers instead.

How do I register global middleware in TanStack Start?

Create src/start.ts and call createStart with a function returning requestMiddleware and functionMiddleware arrays. These middleware run for every server request and every server function respectively across the application.