AUTHENTICATION / LESSON 03
Clerk in Your App.
Social login, protecting pages and adding login buttons in code

Loading the lesson…
Loading activities…
AUTHENTICATION / LESSON 03
Social login, protecting pages and adding login buttons in code

Loading the lesson…
Loading activities…
Ever clicked "Sign in with Google" on a website? That's social login. Instead of making up yet another password, you use an account you already have.
Clerk makes social login easy. You flip it on in your Clerk dashboard, and people can log in with any of these.
Here's a simple example of Clerk in a Next.js app. You don't need to understand every lil detail yet... just notice how SHORT it is.
First, install Clerk's Next.js package from your project folder.
Then make an app in the Clerk dashboard, copy your two keys from its API keys page, and paste them into a .env.local file in your project root.
The secret key stays on the server, so never put it in a NEXT_PUBLIC_ variable. You'll also wrap your app in <ClerkProvider>, which happens in app/layout.tsx (the full file is down in Adding Login Buttons).
Locking pages behind a login starts with Clerk's middleware file. It's called proxy.ts on Next.js 16 and newer, and middleware.ts on Next.js 15 and older (the code inside is the same either way).
That gets Clerk running on every request. Heads up though, on its own it doesn't lock anything. Every route stays public until you add a check.
And Clerk's advice now is to put that check right on the page (or API route) that reads the private data, not in the middleware. One line does it.
Do that on every page and API route that touches private stuff. (you'll see older tutorials protect routes in middleware with createRouteMatcher, but Clerk has deprecated that now)
Once someone's logged in, you can find out who they are.
Clerk hands you info like this.
Clerk also ships ready-made components, so you're not building buttons from scratch. They go in your root layout, inside the <ClerkProvider> that every Clerk app needs.
Run npm run dev, click Sign up, and you've got a working login. Clerk's Next.js quickstart has the same steps if you want to double check anything.