Overview
Clerk handles all authentication concerns including:- User sign-up and sign-in flows
- Session management
- Protected routes via middleware
- Integration with Convex backend
- User profile management
Configure Environment Variables
Set up the required Clerk environment variables in your Get your Clerk keys from the Clerk Dashboard.
.env.local file:Provider Setup
AiVault wraps the application with The
ClerkProvider in the root providers file:app/providers.tsx
ClerkProvider is integrated with Convex using ConvexProviderWithClerk for seamless backend authentication.Configure Convex Integration
AiVault connects Clerk with Convex for authenticated database queries:This configuration enables Convex to verify Clerk authentication tokens.
convex/auth.config.js
Sign Up Flow
AiVault provides a dedicated sign-up page using Clerk’s pre-built component:app/sign-up/[[...sign-up]]/page.tsx
- Email and password registration
- OAuth providers (Google, GitHub, etc.)
- Email verification
- Automatic session creation
- Redirect to dashboard after sign-up
Sign In Flow
The sign-in page uses Clerk’s pre-built component with the same consistent UI:app/sign-in/[[...sign-in]]/page.tsx
- Email and password authentication
- OAuth providers
- “Remember me” option
- Password reset functionality
- Redirect to previous page or dashboard
Conditional UI Rendering
AiVault uses Clerk’sSignedIn and SignedOut components to show different UI based on authentication state:
components/layout/Navbar.tsx
Accessing User Data
Use Clerk’suseAuth hook to access the current user’s authentication state:
Admin Access Control
AiVault implements role-based access control for admin features:Error Handling
If Clerk is not properly configured, AiVault displays a setup screen:Next Steps
User Management
Learn about user profiles, sessions, and account settings
Convex Integration
See how Clerk integrates with Convex queries