start-core-server-functions

Implements type-safe server functions in TanStack Start using createServerFn with validation and error handling.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @tanstack/react-start, @tanstack/react-router, zod.

What problem does it solve? TanStack Start developers need a reliable way to run server-only logic (database queries, secrets, file access) without leaking it into isomorphic loaders or misusing patterns from Next.js and Remix. This Skill provides the correct createServerFn patterns, including auth enforcement, validation, and caching rules. ## Core Features & Use Cases - Server Function Creation: Build GET/POST RPC endpoints with createServerFn, call them from loaders, components, or the useServerFn hook. - Validation & Error Handling: Validate inputs with Zod or plain functions, handle FormData, and throw errors, redirects, or notFound responses. - Security Guardrails: Enforce auth inside handlers via middleware, avoid public caching of authenticated responses, and organize code with .functions.ts and .server.ts files. - Use Case: When building a dashboard that loads user orders, wrap the database query in createServerFn with authMiddleware so the endpoint is protected even if called directly outside the route. ## Quick Start Create a TanStack Start server function that fetches a user by ID with Zod validation and proper auth middleware.

Frequently Asked Questions about start-core-server-functions

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

FAQPage Schema
How do I create a server function in TanStack Start?

Use createServerFn from @tanstack/react-start, optionally set the method to GET or POST, chain a validator, and define the handler. Call it from loaders, components, or other server functions like a normal async function.

How do I validate server function input with Zod?

Pass a Zod schema to the .validator() method of createServerFn. The handler then receives the parsed, type-safe data object, and invalid input is rejected before the handler runs.

Can I put database queries directly in a TanStack Start loader?

No. Loaders are isomorphic and run on both client and server, so database queries and secrets must go inside createServerFn handlers. The loader should call the server function instead.

Does a route beforeLoad guard protect my server functions?

No. Server functions are independent API endpoints reachable without loading the route. Auth must be enforced inside the handler or via middleware on every server function that touches private data.

When should I use the useServerFn hook?

Use useServerFn when the server function throws redirect() or notFound(), since the hook wires the throw into the router. For plain data-returning functions, direct calls or useMutation work fine.

Why is Cache-Control public dangerous for authenticated responses?

Public caching lets CDNs and shared proxies serve one user's response to another, causing cross-tenant data leaks. Use Cache-Control private with a Vary header, or no-store for sensitive data.