Overview
@wacht/tanstack-router adds authentication, user management, and multi-tenancy to TanStack Router applications.
What’s Included
- TanStack Router Integration - Built specifically for TanStack Router
- Type Safety - Full TypeScript support with TanStack Router’s type system
- Authentication Components - Pre-built sign-in, sign-up, and SSO callback components
- Authentication Hooks - Hooks for handling sign-in, sign-up, password reset, and more
- User Management - Hooks and components for profile management
- Organization & Workspace Support - Multi-tenant support with organizations and workspaces
- Session Management - Automatic session handling with token refresh
- Route Loaders - Server-side data fetching with TanStack Router loaders
- Notifications - Real-time notification support with hooks and components
- AI Agents - Hooks for building AI agent features with context and integrations
Installation
Quick Start
1. Create Environment Variables
2. Configure the Provider
3. Create Authentication Routes
4: Protect Routes
5. Add User Menu
Server-Side Data Fetching
TanStack Router supports loaders for server-side data fetching:Getting Session in Loaders
Protected Routes with Auth Check
Configuration
Environment Variables
UI Customization
Components
All components are available directly from the SDK:SignInForm- Sign-in form componentSignUpForm- Sign-up form componentUserButton- User profile dropdownOrganizationSwitcher- Organization/workspace switcherManageAccount- Account managementManageOrganization- Organization managementCreateOrganizationForm- Create organizationCreateWorkspaceForm- Create workspaceSignedIn/SignedOut- Conditional renderingSSOCallback- OAuth callback handlerWaitlistForm- Waitlist signupMagicLinkVerification- Magic link verificationNotificationBell- Notification bellNotificationPopover- Notification dropdownNotificationPanel- Full notification panel
Hooks
All hooks are available directly from the SDK:useSignIn- Handle sign-inuseSignUp- Handle sign-upuseSession- Access sessionuseUser- Manage user profileuseDeployment- Access deployment configuseClient- Access HTTP clientuseNavigation- Manage redirectsuseForgotPassword- Password resetuseMagicLinkVerification- Magic link authuseSSOCallback- OAuth callbacksuseWaitlist- Waitlist signupuseOrganizationList- List organizationsuseActiveOrganization- Active organizationuseOrganizationMemberships- Manage membershipsuseWorkspaceList- List workspacesuseActiveWorkspace- Active workspaceuseWorkspaceMemberships- Workspace membershipsuseNotifications- NotificationsuseNotificationStream- Real-time notificationsuseAgentContext- AI agent contextuseAgentSession- AI agent sessionuseInvitation- Handle invitations
Server-Side Helpers
The TanStack Router SDK includes server-side helpers:getSessionServer
Get the current session server-side:requireAuthServer
Helper to require authentication in loaders:Examples
Protected Route with Loader
Organization Route
Action for Updating Profile
Related
- React Router SDK - React Router SDK documentation
- Next.js SDK - Next.js SDK documentation
- API Reference - Frontend API reference
