clerk-tanstack-patterns

Guard TanStack React Start routes and server handlers with Clerk authentication.

Updated May 4, 2026
One-click install
npx skills add https://github.com/Endsi3g/Uprising-AOS --skill clerk-tanstack-patterns-endsi3g
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: clerk-tanstack-patterns
Source: https://github.com/Endsi3g/Uprising-AOS/tree/main/.agents/skills/clerk-tanstack-patterns
Command: npx skills add https://github.com/Endsi3g/Uprising-AOS --skill clerk-tanstack-patterns-endsi3g

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents unauthorized access in a TanStack React Start app by providing a reliable, server-safe authentication guard pattern for routes and server functions.

Core Features & Use Cases

  • Route protection with beforeLoad: Block unauthenticated users by throwing a redirect during route initialization.
  • Server-side auth via createServerFn: Centralize authentication checks in server-executed functions using Clerk’s auth helper.
  • Shared auth context for loaders: Pass authenticated user data from beforeLoad into loaders so components can render secure, org-aware results.

Quick Start

Ask the Skill: “Show me how to protect the /dashboard route so unauthenticated users are redirected to /sign-in using beforeLoad and createServerFn with Clerk auth.”

Frequently Asked Questions about clerk-tanstack-patterns

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

FAQPage Schema
How do I protect TanStack React Start routes with Clerk authentication?

To protect TanStack React Start routes with Clerk authentication, use the beforeLoad hook to throw a redirect to your sign-in page for unauthenticated users, ensuring server-side route initialization securely blocks unauthorized access.

Why does my TanStack beforeLoad redirect fail to stop unauthenticated access?

Your TanStack beforeLoad redirect fails because you are returning the redirect instead of throwing it. You must throw the redirect during route initialization to properly halt execution and block unauthenticated access.

How do I secure server functions in TanStack React Start using Clerk?

You secure server functions in TanStack React Start by using createServerFn and calling Clerk’s auth helper from @clerk/tanstack-react-start/server to centralize authentication checks within your server-executed handlers.

Does Clerk auth require middleware setup in Vinxi for TanStack Start?

Yes, Clerk auth requires wiring clerkMiddleware() inside the Vinxi startInstance configuration to ensure the server auth context is available for route loaders and server functions across your TanStack application.

What is the best way to pass Clerk auth context to TanStack route loaders?

The best way to pass Clerk auth context to TanStack route loaders is to extract authenticated user data within beforeLoad and pass it down, enabling nested loaders to render secure, organization-aware results.