How Authentication Works
Film Fanatic implements a hybrid authentication model:- Guest Users: Data is stored in
localStoragefor immediate access without sign-in - Authenticated Users: Data automatically syncs to Convex backend for cross-device access
- Automatic Migration: When guests sign in, their local data can be synced to the cloud
Clerk Configuration
1. Create a Clerk Application
- Sign up at clerk.com
- Create a new application
- Choose your authentication methods (Email, Google, GitHub, etc.)
- Copy your API keys from the dashboard
2. Configure Environment Variables
Add these keys to your.env.local file:
3. Set Up Clerk-Convex Integration
Film Fanatic integrates Clerk with Convex for backend authentication. Configure your Clerk issuer URL in the Convex auth config:convex/auth.config.ts
4. Configure Convex Environment Variable
In your Convex dashboard, add the Clerk issuer URL:User Synchronization
Film Fanatic automatically syncs authenticated users to the Convex database.User Sync Component
TheUserSync component runs on every page load to ensure user data is up-to-date:
src/components/user-sync.tsx
User Store Mutation
The backend handles user creation and updates:convex/users.ts
User Profile Data
Clerk provides rich user profile information that Film Fanatic stores:| Field | Source | Description |
|---|---|---|
tokenIdentifier | Clerk user.id | Unique user identifier |
name | Clerk user.fullName or user.username | Display name |
email | Clerk user.primaryEmailAddress | User’s email |
image | Clerk user.imageUrl | Profile picture URL |
Authentication States
Checking Authentication Status
Use the ConvexgetStatus query to check if a user is authenticated:
Protected Mutations
All backend mutations verify authentication before processing:Customizing Authentication
Appearance Customization
You can customize Clerk’s sign-in components to match your brand:Authentication Methods
Configure which sign-in methods are available in your Clerk Dashboard:- Email/Password
- Email verification codes
- Social OAuth (Google, GitHub, etc.)
- Phone number
- Web3 wallets
Security Best Practices
- Store secret keys in environment variables
- Use different Clerk applications for development and production
- Enable two-factor authentication for admin accounts
- Regularly rotate API keys
- Monitor authentication logs in Clerk dashboard
Troubleshooting
”Called storeUser without authentication present”
This error occurs when a mutation is called without a valid session:- Ensure the user is signed in before calling protected mutations
- Verify Clerk is properly initialized
- Check that
CONVEX_CLERK_ISSUER_URLmatches your Clerk domain
User not syncing to database
- Verify the
UserSynccomponent is rendered in your app root - Check that Clerk and Convex credentials are correctly configured
- Ensure the Convex auth config has the correct issuer URL
Session expires too quickly
Configure session lifetime in Clerk Dashboard → Sessions:- Adjust “Inactive session lifetime”
- Enable “Multi-session handling” for concurrent logins
