Clerk Authentication
Clerk provides authentication, user management, and session handling for Mantlz.Features
- Email/password authentication
- Social login (Google, GitHub, etc.)
- Multi-factor authentication
- User profile management
- Session management
- Organization support
Setup
Create a Clerk application
- Sign up at clerk.com
- Create a new application
- Choose a name for your application
- Select authentication methods
Configure authentication methods
In your Clerk dashboard:
- Go to User & Authentication → Email, Phone, Username
- Enable email addresses
- Configure password requirements
- (Optional) Enable social providers under Social Connections
Middleware Configuration
Mantlz uses Clerk middleware for route protection:src/middleware.ts
Protected Routes
The following routes are protected by default:/dashboard/*- Main dashboard/api/trpc/*- tRPC API routes/api/webhooks/*(except Stripe webhooks)
See
src/utils/routes.ts for the complete list of protected routes.Stripe Payment Integration
Stripe handles subscription billing, payment processing, and customer management.Features
- Subscription management
- Payment processing
- Customer portal
- Webhook events
- Invoice generation
- Failed payment handling
Setup
Create a Stripe account
Sign up at stripe.com and complete account verification.
Create subscription products
In your Stripe dashboard:
- Go to Products → Add product
- Create a “Standard” plan:
- Name: Standard
- Recurring billing: Monthly
- Price: Your chosen amount
- Create a “Pro” plan:
- Name: Pro
- Recurring billing: Monthly
- Price: Your chosen amount
- Copy the price IDs for each plan
Set up webhooks
See the Webhooks Guide for detailed webhook configuration.
Checkout Session Creation
Mantlz creates Stripe checkout sessions for subscription upgrades:Subscription Plans
Mantlz supports three subscription tiers:Customer Portal
Mantlz provides access to the Stripe customer portal for subscription management:Resend Email Service
Resend handles all transactional emails from Mantlz.Email Types
- Welcome emails for new users
- Form submission notifications
- Campaign emails
- Payment receipts
- Subscription updates
- Password resets
Setup
Create a Resend account
Sign up at resend.com
Add and verify your domain
- Go to Domains → Add Domain
- Enter your domain (e.g.,
mantlz.app) - Add the provided DNS records to your domain:
- SPF record
- DKIM record
- Custom domain MX records
- Wait for verification (usually takes a few minutes)
Sending Emails
Example email sending with Resend:Email Templates
Mantlz uses React Email for email templates:Sanity CMS
Sanity provides headless CMS functionality for blog posts and marketing content.Configuration
Client Setup
src/sanity/env.ts
Sanity is optional. If you’re not using the blog/marketing features, you can skip this integration.
Upstash Redis (Rate Limiting)
Upstash Redis provides serverless rate limiting.Setup
Create an Upstash account
Sign up at upstash.com
Create a Redis database
- Click Create Database
- Choose a name
- Select a region (choose closest to your deployment)
- Click Create
Rate Limit Configuration
src/lib/ratelimiter.ts
PostHog Analytics
PostHog provides product analytics and feature flags.Setup
Create a PostHog account
Sign up at posthog.com or use PostHog Cloud
Client Configuration
src/lib/posthog.ts
Sentry Error Tracking
Sentry provides error tracking and performance monitoring.Setup
Create a Sentry project
- Sign up at sentry.io
- Create a new project
- Select Next.js as the platform
Configuration Files
Sentry configuration is already set up in:sentry.edge.config.ts- Edge runtime configurationsentry.server.config.ts- Server runtime configuration
Uploadcare (File Uploads)
Uploadcare handles file uploads for form submissions.Setup
File uploads are optional. Forms will still work without Uploadcare, but file upload fields will be disabled.
Integration Checklist
Required for Core Functionality
- Clerk - User authentication
- Stripe - Payment processing
- Resend - Email delivery
- PostgreSQL - Database
Optional Enhancements
- Upstash Redis - Rate limiting
- PostHog - Product analytics
- Sentry - Error tracking
- Sanity - Blog/marketing content
- Uploadcare - File uploads
Troubleshooting
Clerk authentication redirects not working
Clerk authentication redirects not working
- Verify
NEXT_PUBLIC_APP_URLis set correctly - Check that redirect URLs in Clerk dashboard match your environment variables
- Ensure allowed origins include your domain
- Clear browser cookies and try again
Stripe checkout fails
Stripe checkout fails
- Verify you’re using the correct API keys (test vs production)
- Check that price IDs match your Stripe products
- Ensure
NEXT_PUBLIC_APP_URLis set correctly for callbacks - Check Stripe dashboard logs for error details
Emails not sending
Emails not sending
- Verify Resend API key is correct
- Check that your domain is verified in Resend
- Ensure from address uses your verified domain
- Check Resend dashboard for delivery logs
- Verify DNS records are correctly configured
Rate limiting not working
Rate limiting not working
- Confirm Upstash Redis credentials are correct
- Test Redis connection
- Check that middleware is properly configured
- Verify rate limit values are set correctly
Next Steps
Webhooks
Configure webhook endpoints for Stripe and other services
Environment Setup
Complete environment variable reference
Self-Hosting
Deploy Mantlz on your infrastructure
API Reference
Explore the Mantlz API