Overview
Clerk provides authentication and user management for the collaborative editor. It handles sign-in, sign-up, and session management with a customizable UI theme.Installation
The project uses the following Clerk packages:package.json
Environment Variables
Add these environment variables to your.env.local file:
Configuration
Root Layout
Clerk is initialized inapp/layout.tsx with a custom dark theme:
app/layout.tsx
ClerkProvider wraps the entire application, enabling authentication throughout all routes.
Middleware
Clerk middleware protects routes automatically:middleware.ts
- All routes are protected except static files
- API routes require authentication
- Next.js internals (
_next) are excluded
Usage in the Application
Getting Current User
UsecurrentUser() to retrieve authenticated user data server-side:
app/api/liveblocks-auth/route.ts to authenticate users for Liveblocks real-time collaboration.
Theme Customization
The application uses Clerk’s dark theme with custom branding:The
#3371FF blue matches the application’s overall design system for a cohesive user experience.Key Features
- Pre-built Components: Sign-in, sign-up, and user profile UI
- Session Management: Automatic token refresh and session handling
- Server-side Auth: Secure user data retrieval via
currentUser() - Route Protection: Middleware-based authentication
- Theme Consistency: Dark mode with custom brand colors