Overview
@wacht/nextjs adds authentication, user management, and multi-tenancy to Next.js applications.
What’s Included
- App Router Support - Built for Next.js App Router (Next.js 14+)
- Server Components - Full support for React Server Components
- 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
- Middleware Support - Built-in middleware for route protection
- 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
- 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 Provider (App Router)
Create a client component for the provider:3. Create Sign-In and Sign-Up Pages
4. Protect Routes with Middleware
Create middleware for route protection:5. Use Server Components
Configuration
Environment Variables
UI Customization
Server-Side Helpers
The Next.js SDK includes server-side helpers for App Router:getSession
Get the current session server-side:requireAuth
Helper to require authentication: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
Examples
Protected Server Component
Client Component with Hooks
Server Actions
Related
- React Router SDK - React Router SDK documentation
- TanStack Router SDK - TanStack Router SDK documentation
- API Reference - Frontend API reference
