Overview
Ticket Hub uses Clerk for authentication and user management. Clerk provides secure, production-ready authentication with social logins, email/password, and magic links out of the box.Clerk Setup
Create a Clerk account
If you don’t have one already, sign up at clerk.com.
Create a new application
In your Clerk dashboard:
- Click + Create Application
- Name it “Ticket Hub” (or your preferred name)
- Select your preferred authentication methods
- Click Create Application
Copy API keys
From your Clerk dashboard, copy the following keys:
- Publishable Key - Used in the client-side code
- Secret Key - Used server-side (keep this secure!)
.env.local file:Set up webhooks
Clerk webhooks keep your Convex database in sync with user changes.
- In Clerk dashboard, go to Webhooks
- Click + Add Endpoint
- Enter your endpoint URL:
https://your-app.vercel.app/api/webhooks/clerk - Subscribe to these events:
user.createduser.updateduser.deleted
- Copy the Signing Secret
.env.local:Convex Auth Configuration
Ticket Hub integrates Clerk with Convex for secure backend authentication.Auth Config File
The Convex auth configuration is defined inconvex/auth.config.ts:
convex/auth.config.ts
Replace the
domain with your Clerk Frontend API URL from your Clerk dashboard under API Keys → Advanced.How It Works
- Client Authentication: Users sign in through Clerk’s UI components
- Token Generation: Clerk generates a JWT token
- Convex Validation: The token is sent with Convex requests and validated
- User Context: Authenticated user info is available in Convex functions
Middleware Configuration
The Next.js middleware protects routes and handles authentication:src/middleware.ts
The middleware automatically protects all routes except static assets and Next.js internals. Public routes can be configured in Clerk dashboard.
Root Layout Integration
Clerk is integrated in the root layout (src/app/layout.tsx):
src/app/layout.tsx
Key Components
ClerkProvider
Wraps the entire app and provides authentication context
ClerkLoading
Shows a loading state while Clerk initializes
ClerkLoaded
Renders content only after Clerk is ready
ConvexClientProvider
Integrates Clerk auth tokens with Convex
Using Authentication in Your Code
Client-Side
Access user information in React components:Server-Side (Convex)
Authenticate Convex mutations and queries:convex/events.ts
Customization
Appearance
Customize Clerk’s UI to match your brand:Protected Routes
Protect specific routes in your Clerk dashboard:- Go to Authentication → Routes
- Add protected routes:
/seller,/tickets - Set public routes:
/,/event/*,/search
Environment Variables Summary
Your Clerk publishable key (public, client-side)
Your Clerk secret key (private, server-side)
Webhook signing secret for verifying Clerk webhooks
Path to your sign-in page (default:
/sign-in)Path to your sign-up page (default:
/sign-up)Troubleshooting
'Clerk: auth() or currentUser() called but Clerk is not installed'
'Clerk: auth() or currentUser() called but Clerk is not installed'
Make sure
ClerkProvider wraps your entire app in the root layout.Infinite redirect loop
Infinite redirect loop
Check that your sign-in/sign-up URLs match in both:
- Your
.env.localfile - Clerk dashboard → Paths
Webhook not receiving events
Webhook not receiving events
Verify:
- Your webhook URL is publicly accessible (use ngrok for local development)
- The signing secret matches your
.env.local - The correct events are subscribed in Clerk dashboard
User data not syncing to Convex
User data not syncing to Convex
Check your webhook handler implementation and ensure it’s processing
user.created, user.updated, and user.deleted events correctly.Next Steps
Environment Setup
Configure all required environment variables
User API
Learn about user queries and management