Founderflow Logo

Authentication System

Complete authentication system powered by Clerk with social login, email/password authentication, and user management.

Clerk Integration

The boilerplate uses Clerk for authentication with the following features:

Social Login

Google, GitHub, and other social providers

Email/Password

Traditional authentication methods

User Management

Profile management and settings

Session Handling

Automatic session management

Webhook Integration

User sync with database

Protected Routes

Automatic route protection

Authentication Flow

1

User Signs Up/In

User authenticates via Clerk using social login or email/password

2

Webhook Creates User

Clerk webhook automatically creates/updates user record in MongoDB

3

Data Synchronized

User data is synchronized across Clerk and your database

4

Protected Routes

Protected routes and API endpoints are automatically handled

Environment Variables

Configure these environment variables for Clerk authentication:

.env
# Clerk Authentication
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
CLERK_SECRET_KEY=sk_test_...
CLERK_WEBHOOK_SIGNING_SECRET=whsec_...

Publishable Key

Used on the client-side for Clerk components

Secret Key

Used on the server-side for API calls

Webhook Secret

Verifies webhook authenticity

Key Files

middleware.ts

Route protection and authentication middleware

/middleware.ts

app/api/webhook/clerk/route.ts

Webhook handler for user synchronization

/app/api/webhook/clerk/route.ts

components/auth/

Authentication components and forms

/components/auth/

Setup Guide

1. Create Clerk Application

  1. Visit clerk.com and create an account
  2. Create a new application
  3. Configure your authentication methods (social providers, email/password)
  4. Copy your API keys from the dashboard

2. Configure Environment Variables

Add your Clerk keys to the .env file as shown above.

3. Set Up Webhooks

  1. In Clerk dashboard, go to Webhooks
  2. Create a new webhook endpoint: https://yourdomain.com/api/webhook/clerk
  3. Subscribe to user events (created, updated, deleted)
  4. Copy the webhook signing secret