DEV Community

Arhan Khan
Arhan Khan

Posted on

Clerk for Beginners: Add Sign-In to Your App Without Building Auth

Authentication is one of those features every app needs and almost nobody enjoys building. Passwords, sessions, email verification, social logins, password resets — each one is a small project, and each one is a security risk if you get it wrong. Clerk is a hosted service that handles all of it, so you can add sign-in to your app in an afternoon.

Clerk gives you ready-made sign-in and sign-up components, user management, social logins (Google, GitHub, and more), and multi-factor authentication. Your app talks to Clerk's API, and Clerk stores the sensitive parts — passwords and tokens — so you never have to.

Here is how simple it looks in a React app:

import { SignedIn, SignedOut, SignInButton, UserButton } from "@clerk/clerk-react";

export default function Header() {
  return (
    <header>
      <SignedOut>
        <SignInButton />
      </SignedOut>
      <SignedIn>
        <UserButton />
      </SignedIn>
    </header>
  );
}
Enter fullscreen mode Exit fullscreen mode

That is the whole sign-in flow. SignedIn and SignedOut show different content depending on the user's state, SignInButton opens Clerk's sign-in screen, and UserButton shows the user's avatar with a menu for profile and sign-out. On the server side, Clerk gives you helpers to check the user's session and protect routes.

To start, create a free account at Clerk, create an application, copy the publishable and secret keys into your environment variables, and install the SDK for your framework — React, Next.js, Vue, and others are all supported.

Clerk is a great fit if you are building a product and want authentication done properly without spending weeks on it. It is especially useful for small teams and solo developers, where building auth from scratch is the most expensive distraction.

The limits are the usual ones for a hosted service. You depend on Clerk being available, and the free tier has limits on monthly active users. If you ever need to leave, migrating users takes planning. For most projects, that trade-off is worth it.

Add Clerk to your next side project instead of building your own login page. The time you save is the time you spend on the features that actually make your app different.

Top comments (0)