router-core/auth-and-guards

Enforce authentication and RBAC on TanStack Router routes with beforeLoad and redirects.

6|1|Updated Jun 1, 2025
One-click install
npx skills add https://github.com/rezics/rezics --skill router-core-auth-and-guards-rezics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: router-core/auth-and-guards
Source: https://github.com/rezics/rezics/tree/main/.agents/skills/tanstack/router/router-core/auth-and-guards
Command: npx skills add https://github.com/rezics/rezics --skill router-core-auth-and-guards-rezics

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Route protection for TanStack Router apps, providing beforeLoad guards, redirects, and RBAC integration to secure client-side routes and authentication flows.

Core Features & Use Cases

  • 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.
  • Use Cases: Protect admin dashboards, guard user pages, enforce role-based access controls across route trees.

Quick Start

Wrap protected routes in an _authenticated layout and connect a live auth context to guard access.

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 checks?

Implement route protection in TanStack Router using beforeLoad guards to verify auth state and redirect unauthenticated users. You can wrap secured pages in an _authenticated layout route to centrally enforce access control.

How does RBAC integration work for TanStack Router route guards?

RBAC integration in TanStack Router guards works by checking user roles and permissions within the beforeLoad hook, blocking or redirecting access when permissions are insufficient. This secures specific routes like admin dashboards based on assigned roles.

Can I use Clerk, Auth0, or Supabase as an auth provider with TanStack Router guards?

Yes, you can integrate auth providers like Clerk, Auth0, and Supabase with TanStack Router guards. The implementation connects your live auth context to the router context, allowing beforeLoad hooks to read provider state and enforce access.

What is the best way to redirect unauthenticated users in TanStack Router?

The best way to redirect unauthenticated users in TanStack Router is using the redirect() or throw redirect() functions within the beforeLoad guard. The isRedirect helper can then catch and manage these redirect flows appropriately.

Do I need an _authenticated layout route to secure TanStack Router pages?

No, an _authenticated layout route is not strictly required, but it is recommended for grouping protected pages. You can also use non-redirect auth or inline login patterns to guard individual routes without a dedicated layout.