router-core/auth-and-guards

Implement route protection and redirect guards in TanStack Router apps.

Updated Apr 1, 2026
One-click install
npx skills add https://github.com/cill-i-am/task-tracker --skill router-core-auth-and-guards-cill-i-am
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core/auth-and-guards
Source: https://github.com/cill-i-am/task-tracker/tree/main/.agents/skills/tanstack-router-auth-and-guards
Command: npx skills add https://github.com/cill-i-am/task-tracker --skill router-core-auth-and-guards-cill-i-am

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Route protection with beforeLoad, redirect()/throw redirect(), isRedirect helper, authenticated layout routes (_authenticated), non-redirect auth (inline login), RBAC with roles and permissions, auth provider integration (Auth0, Clerk, Supabase), router context for auth state.

Core Features & Use Cases

  • Protect routes with beforeLoad and redirect logic to guard access
  • Implement authenticated layouts, RBAC, and provider integrations
  • Use router context to share auth state across routes and loaders

Quick Start

Add a pathless _authenticated layout with a beforeLoad guard that redirects unauthenticated users to /login.

Frequently Asked Questions about router-core/auth-and-guards

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

FAQPage Schema
How do I protect routes in TanStack Router with authentication guards?

Protect routes in TanStack Router by adding a beforeLoad guard to your route definition that checks auth state and calls redirect() to send unauthenticated users to the login page. This mechanism safely restricts access to specific route paths.

What is the best way to implement RBAC role-based access control in TanStack Router?

Implement RBAC in TanStack Router by evaluating user roles and permissions inside the beforeLoad guard. You can redirect unauthorized users away from restricted routes, securing the application based on specific permission sets.

How does TanStack Router handle redirect errors during route guard checks?

TanStack Router uses the isRedirect helper to handle redirect exceptions during beforeLoad guards. This allows you to safely manage and catch redirects thrown by route protection logic without crashing the application.

Can I use TanStack Router auth guards with external providers like Clerk or Supabase?

Yes, TanStack Router auth guards work with external providers like Auth0, Clerk, and Supabase. You integrate the provider's auth state into the router context, making it available to beforeLoad guards for access control decisions.

How do I share authentication state across loaders in TanStack Router?

Share authentication state across loaders by storing it in the TanStack Router context. This makes the current auth status globally available to all route loaders and beforeLoad guards throughout your application routing tree.

When should I use an authenticated layout route in TanStack Router?

Use an authenticated layout route, such as a pathless _authenticated route, when you need to apply a single beforeLoad guard across multiple child routes. This pattern centralizes redirect logic for unauthenticated users efficiently.