Skip to content

Instantly share code, notes, and snippets.

@Krishprajapati15
Created June 24, 2025 10:54
Show Gist options
  • Select an option

  • Save Krishprajapati15/68561d96e97017795d39fe0f526d674d to your computer and use it in GitHub Desktop.

Select an option

Save Krishprajapati15/68561d96e97017795d39fe0f526d674d to your computer and use it in GitHub Desktop.
Clerk provides a complete, easy-to-use authentication and user management solution for modern web and mobile applications. It offers prebuilt components, secure APIs, and full support for popular frameworks—letting you add sign up, sign in, user profiles, social login, and more in minutes.

Clerk Auth: Simple Authentication for Modern Apps

Clerk provides a complete, easy-to-use authentication and user management solution for modern web and mobile applications. It offers prebuilt components, secure APIs, and full support for popular frameworks—letting you add sign up, sign in, user profiles, social login, and more in minutes.


🚀 Key Features

  • Prebuilt UI Components – Drop-in sign up, sign in, user profile, and multi-factor authentication widgets.
  • Social, Passwordless, and Magic Link Logins – Easily enable Google, GitHub, Twitter, and email/passwordless login.
  • User Management – Built-in dashboard for managing users, roles, and sessions.
  • Secure APIs – Protect your backend routes and resources with Clerk's authentication middleware and JWTs.
  • Framework Integrations – First-class support for Next.js, React, Remix, Expo/React Native, and more.
  • Customizable – Fully customizable UI and workflows to fit your brand and requirements.

🛠️ How to Use Clerk Auth

  1. Sign Up & Create an Application

    • Go to clerk.com and sign up for a free account.
    • Create a new application in the Clerk dashboard.
  2. Integrate Clerk into Your App

    • Install the Clerk SDK for your stack (e.g., React, Next.js, etc.).
    • Example for Next.js:
      npm install @clerk/clerk-react
  3. Add Clerk Provider & Components

    • In your app’s root, wrap your code with <ClerkProvider>.
    • Add authentication components like <SignIn />, <SignUp />, and <UserButton /> where needed.
    • Example (React):
      import { ClerkProvider, SignIn, SignUp, UserButton } from "@clerk/clerk-react";
      
      function App() {
        return (
          <ClerkProvider>
            <SignIn path="/sign-in" routing="path" />
            <SignUp path="/sign-up" routing="path" />
            <UserButton />
            {/* Your app routes */}
          </ClerkProvider>
        );
      }
  4. Protect Backend APIs

    • Use Clerk’s middleware or SDK to secure API routes and get the authenticated user.
    • Example (Next.js API route):
      import { getAuth } from "@clerk/nextjs/server";
      
      export default function handler(req, res) {
        const { userId } = getAuth(req);
        if (!userId) {
          return res.status(401).json({ error: "Unauthorized" });
        }
        // ...your code
      }
  5. User Management

    • Use Clerk’s dashboard to view and manage users, sessions, and roles.
    • Programmatically manage users and data with Clerk’s REST API or Admin SDK.

💡 When to Use Clerk Auth

  • New projects: Quickly add robust authentication to web/mobile apps without building from scratch.
  • MVPs or Startups: Save development time and ensure security best practices.
  • Apps needing social login: Easily enable Google, GitHub, Twitter, and other OAuth providers.
  • SaaS platforms: Out-of-the-box support for user profiles, roles, organization management, and multi-tenancy.
  • Projects requiring secure API access: Protect backend endpoints and resources using JWTs and Clerk middleware.
  • Apps with custom branding: Clerk’s UI is fully customizable to match your app’s look and feel.

🖥️ Example: Adding Clerk Auth to a Next.js App

# 1. Install Clerk packages
npm install @clerk/nextjs

# 2. Add ClerkProvider in _app.js/_app.tsx
import { ClerkProvider } from "@clerk/nextjs";

export default function MyApp({ Component, pageProps }) {
  return (
    <ClerkProvider>
      <Component {...pageProps} />
    </ClerkProvider>
  );
}

# 3. Add sign in/up components in your pages:
import { SignIn, SignUp } from "@clerk/nextjs";

export default function SignInPage() {
  return <SignIn />;
}

export default function SignUpPage() {
  return <SignUp />;
}

📚 Resources


Learn more at clerk.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment