🚀 Clerk Auth Reference

🔍

Get Started in Minutes

⚛️ Next.js Popular
Full-stack React framework with built-in routing and API support
npm install @clerk/nextjs
npx create-next-app@latest --example with-clerk
⚛️ React
Build interactive UIs with the most popular JavaScript library
npm install @clerk/clerk-react
npm create vite@latest my-app -- --template react
🟩 Vue
Progressive JavaScript framework for building user interfaces
npm install @clerk/vue
npm create vue@latest
📱 Expo Mobile
Build native mobile apps with React Native
npm install @clerk/clerk-expo
npx create-expo-app
🚂 Express.js
Fast, unopinionated web framework for Node.js
npm install @clerk/express
npm install express
💎 Remix
Full-stack web framework focused on web standards
npm install @clerk/remix
npx create-remix@latest

🧩 Pre-built Components

🔑 Sign In
Ready-to-use sign-in component with customizable appearance
import { SignIn } from "@clerk/nextjs";

📝 Sign Up
Complete sign-up flow with email verification
import { SignUp } from "@clerk/nextjs";

👤 User Button
User avatar with dropdown menu for account management
import { UserButton } from "@clerk/nextjs";

🏢 Organization Switcher
Switch between multiple organizations
import { OrganizationSwitcher } from "@clerk/nextjs";

🛡️ Protected Routes
Protect pages and components based on auth status
import { Protect } from "@clerk/nextjs";


  
🔄 Conditional Rendering
Show content based on authentication state
import { SignedIn, SignedOut } from "@clerk/nextjs";

Welcome back!
Please sign in

🔒 Authentication Methods

🌐 Social Connections
OAuth providers like Google, GitHub, Discord, and more
🏢 Enterprise SSO Premium
SAML and OIDC for enterprise authentication
🦊 Web3 Wallets
MetaMask, Coinbase Wallet, and other Web3 providers
🔐 Security Features
Built-in protection against common vulnerabilities
⚙️ Configuration
Customize authentication options and requirements
📋 Compliance
GDPR, CCPA, and legal compliance features

🔗 Database & Platform Integrations

🔥 Firebase
Sync authentication with Firebase Auth and Firestore
Supabase
Row-level security with Supabase
🌊 Convex
Real-time database integration
🛍️ Shopify
E-commerce authentication integration
Vercel
Deploy with Vercel Marketplace integration
📊 Google Analytics
Track authentication events

💡 Ready-to-Use Code Examples

🔧 Next.js Middleware
Protect routes with middleware
// middleware.ts
import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

const isProtectedRoute = createRouteMatcher([
  '/dashboard(.*)',
  '/api/protected(.*)',
])

export default clerkMiddleware((auth, req) => {
  if (isProtectedRoute(req)) auth().protect()
})

export const config = {
  matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'],
}
🎨 Custom Sign-In Page
Create a custom-styled sign-in page
// app/sign-in/[[...sign-in]]/page.tsx
import { SignIn } from "@clerk/nextjs";

export default function Page() {
  return (
    
  );
}
🔒 Protected API Route
Secure your API endpoints
// app/api/protected/route.ts
import { auth } from "@clerk/nextjs/server";

export async function GET() {
  const { userId } = auth();
  
  if (!userId) {
    return new Response("Unauthorized", { status: 401 });
  }
  
  return Response.json({ message: "Protected data", userId });
}
🪝 useUser Hook
Access user data in React components
// components/UserProfile.tsx
import { useUser } from "@clerk/nextjs";

export function UserProfile() {
  const { isLoaded, isSignedIn, user } = useUser();
  
  if (!isLoaded) return 
Loading...
; if (!isSignedIn) return
Not signed in
; return (

Welcome, {user.fullName}!

Email: {user.primaryEmailAddress?.emailAddress}

); }
🏢 Organization Context
Work with organizations
import { useOrganization } from "@clerk/nextjs";

export function OrgDashboard() {
  const { organization, isLoaded } = useOrganization();
  
  if (!isLoaded) return 
Loading...
; if (!organization) return
No organization selected
; return

{organization.name} Dashboard

; }
🔄 Server-Side Auth
Get user data on the server
// app/dashboard/page.tsx
import { auth, currentUser } from "@clerk/nextjs/server";

export default async function DashboardPage() {
  const { userId } = auth();
  const user = await currentUser();
  
  if (!userId) {
    redirect('/sign-in');
  }
  
  return 

Welcome, {user?.firstName}!

; }

📖 Documentation & Support

📚 Main Documentation
Complete documentation and guides
🎯 Dashboard
Manage your applications and settings
💬 Community
Get help from the community
💰 Pricing
Plans and pricing information
🐙 GitHub
Official SDKs and examples
🔧 Troubleshooting
Common issues and solutions
?