Overview
A production-ready password-based authentication system for TanStack Start built on Convex Auth. Includes login, sign-up, email verification, password reset, and protected routes with full server-side and client-side implementations.Features
- Email and password authentication
- Email verification via magic links
- Password reset flow
- Protected route patterns
- Loading and error states
- Form validation
- Automatic redirects
- Server-side auth checks
- Type-safe with TypeScript
Installation
What Gets Installed
Components
login-form.tsx- Email/password login formsign-up-form.tsx- User registration formforgot-password-form.tsx- Request password resetupdate-password-form.tsx- Set new passwordlogout-button.tsx- Sign out button
Routes
routes/auth/login.tsx- Login pageroutes/auth/sign-up.tsx- Sign-up pageroutes/auth/forgot-password.tsx- Password reset requestroutes/auth/update-password.tsx- Reset password handlerroutes/auth/sign-up-success.tsx- Email verification promptroutes/_protected/index.tsx- Example protected route
Backend (Convex)
convex/schema.ts- Database schema for usersconvex/auth.ts- Auth query endpointsconvex/auth.config.ts- Auth configurationconvex/users.ts- User queriesconvex/http.ts- HTTP endpoints for auth callbacks
Environment Variables
Client (.env)
Your Convex deployment URL
Your Convex deployment name
Server (Convex Dashboard)
Resend API key for sending verification and reset emails
Sender email address (defaults to
[email protected])Usage
Basic Login Form
routes/auth/login.tsx
Sign-Up Form
routes/auth/sign-up.tsx
Protected Routes
Create a route group with authentication checks:routes/_protected.tsx
Logout Button
Authentication Flow
API Reference
LoginForm Props
The login form is a standalone component with no required props:- Email and password inputs
- Client-side validation
- Loading states
- Error handling
- Auto-redirect on success
- Link to sign-up page
- Link to forgot password
SignUpForm Props
The sign-up form is also standalone:- Email and password inputs
- Confirm password field
- Password strength indicator
- Terms acceptance checkbox
- Client-side validation
- Auto-redirect to verification page
Auth Actions
Access auth methods using Convex Auth hooks:Backend Implementation
Auth Configuration
Theconvex/auth.config.ts file configures password authentication:
User Queries
Theconvex/users.ts file provides user data access:
Customization
Custom Email Templates
Modify email content inconvex/auth.ts:
Style Customization
The forms use shadcn/ui components. Customize via your theme:Redirect Paths
Change redirect destinations in form components:Security Best Practices
- Passwords are hashed using industry-standard algorithms
- Verification tokens expire after 24 hours
- Reset tokens are single-use
- Rate limiting should be added for production
- CSRF protection is built-in
Troubleshooting
Verification emails not sending
Verification emails not sending
- Check that
AUTH_RESEND_KEYis set in Convex dashboard - Verify your Resend domain is configured
- Check Convex logs for email errors
Cannot read properties of undefined (reading 'signIn')
Cannot read properties of undefined (reading 'signIn')
Ensure your app is wrapped with
ConvexClientProvider from lib/convex/provider.tsx.Redirect not working after login
Redirect not working after login
Make sure you’re using TanStack Router’s
useNavigate hook correctly and the target route exists.TypeScript errors on api imports
TypeScript errors on api imports
Run
npx convex dev to generate type definitions from your schema.Related Components
- Social Authentication - Add OAuth providers
- Current User Avatar - Display authenticated user
- Convex Client Setup - Configure Convex with TanStack Start