auth-server-primitives

Implements server-side session cookies, OAuth, CSRF, and rate limiting for TanStack Start.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Building secure authentication on the server side of a TanStack Start app requires correctly handling session cookies, OAuth flows, CSRF defense, and rate limiting, and mistakes in any of these create exploitable vulnerabilities.

Core Features & Use Cases

  • Session Management: Issue, read, and destroy HttpOnly, Secure, SameSite session cookies with the __Host- prefix, including session rotation on privilege changes.
  • OAuth Hardening: Implement the authorization-code flow with one-time state and PKCE verifiers stored in short-lived signed cookies.
  • Attack Defenses: Apply CSRF origin checks for non-GET RPCs, rate limit login and reset endpoints, and defeat user enumeration in password-reset flows.
  • Use Case: When adding login to a TanStack Start app, use this Skill to wire an authMiddleware that loads the session per request, enforce auth inside every server function handler, and rotate sessions on login and password change.

Quick Start

Implement secure login, logout, and session handling for my TanStack Start app using createServerFn with auth middleware and hardened session cookies.

Frequently Asked Questions about auth-server-primitives

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

FAQPage Schema
How do I implement session authentication in TanStack Start?

Store the session token in an HttpOnly, Secure, SameSite=Lax cookie with the __Host- prefix, then load it in a createMiddleware server function that attaches the session to context. Apply that middleware to every server function that touches private data.

How do I protect server functions in TanStack Start from unauthenticated calls?

Enforce auth inside the server function handler or via middleware, not in route beforeLoad guards. Route guards only affect page navigation; RPC endpoints remain directly callable, so each protected createServerFn needs its own auth check.

Does SameSite=Lax fully prevent CSRF on POST requests?

SameSite=Lax blocks most cross-site POST CSRF but does not block requests from sibling subdomains. For non-GET requests, also verify the Origin header matches your app's full origin in middleware.

How do I prevent user enumeration in password reset endpoints?

Return the same 200 response and identical body whether or not the email exists, and perform equivalent work in both branches to avoid timing leaks. Never use different messages or status codes for registered versus unregistered emails.

Why does reading cookies or env vars at module scope break in TanStack Start?

Module-level code runs before any request exists, so request headers are unavailable, and on edge runtimes like Cloudflare Workers environment variables are injected per request. Read cookies and secrets inside handler or middleware callbacks instead.