Authentication Guide for AI Coders
How to add login, signup, and user management to your web app. Protect data, personalize experiences, and control access: your Backend handles this with API routes and Middleware. You'll also want a database to store user information.
In this chapter
- Whether your app actually needs login (many don't!)
- The difference between authentication and authorization
- Which auth service to use (Clerk, Supabase, Better Auth)
- How to ask your AI tool to add login to your app
Why Authentication Matters
Auth Providers Compared
- Easiest setup: add components and it works
- Beautiful pre-built UI (SignIn, SignUp, UserButton)
- Generous free tier (50,000 monthly retained users per app)
- Paid plans can get expensive at scale
- Less control over the auth UI
- Completely free and open source
- Supports Google, GitHub, Apple and many more login services
- Full control over database and session handling
- More setup and configuration required (your AI tool can help)
- Integrated with Supabase database and storage
- Controls who can see what data for fine-grained access
- Magic link (passwordless) login built in
- Tied to the Supabase ecosystem
- UI components are more basic
- Excellent mobile support (iOS, Android, Flutter)
- Phone number authentication built in
- Backed by Google infrastructure
- Tied to the Firebase/Google ecosystem
- Can be complex to set up with Next.js
What Auth Screens Look Like
Visual mockups of the most common authentication UI patterns you'll build.
Welcome back
Sign in to your account
Don't have an account? Sign up
Create an account
Get started for free
Logged-in user menu pattern
Jane Doe
jane@example.com
Key Concepts
Quick Start with Clerk
The fastest way to add login to your app. No coding knowledge needed: just follow these steps and let your AI tool do the heavy lifting.
-
1
Create a Clerk account Go to clerk.com and sign up for a free account. Create a new application and pick which login methods you want (Google, GitHub, email, etc.).
-
2
Copy your API keys In the Clerk dashboard, find your API keys (they look like long strings of letters and numbers). You'll need two: a "Publishable Key" and a "Secret Key". Keep these private: they connect your app to Clerk.
-
3
Tell your AI tool to set up ClerkTell your AI tool:
“Add Clerk authentication to my Next.js app. Use these API keys: [paste your keys]. Set up Google and GitHub login. Add a sign-in page at /sign-in and a sign-up page at /sign-up.”
-
4
Ask your AI tool to protect pagesTell your AI tool:
“Make the /dashboard and /settings pages require login. If someone isn't signed in, send them to the /sign-in page.”
-
5
Add a user menu to your navigationTell your AI tool:
“Add a user button to the top-right corner of my navbar. When someone is logged in, show their avatar. When they click it, show a dropdown with profile, settings, and sign-out options. Use Clerk's UserButton component.”
Common Auth Patterns
AI Prompts for Auth
Copy-paste these into your AI tool (Claude Code, Cursor, Bolt, etc.) to add login features to your app.
“Add Google and GitHub login to my app using Clerk. Create a sign-in page and a sign-up page with social login buttons.”
“Make my dashboard and settings pages require login. If someone isn't signed in, send them to the sign-in page.”
“Add a user avatar button to the top-right corner of my navbar. When clicked, show a dropdown with profile, settings, and sign-out options.”
“Set up role-based access so admin users can see an admin page, but regular users get redirected away from it.”
“Add email and password login to my app using Better Auth. Include a custom sign-in page with email and password fields.”
Prompt This
Copy-paste these prompts into your AI tool to apply what you just learned.
“Add user authentication to my Next.js app using Clerk. Include sign-up, sign-in, and a protected dashboard page. Add Google and GitHub as social login options.”
“Protect my [dashboard/settings/admin] pages so only logged-in users can access them. Redirect unauthenticated users to the login page.”
“Add user roles to my app (admin, editor, viewer). Admin users can access the /admin page. Editors can create and edit content. Viewers can only read. Show different navigation items based on role.”
Frequently Asked Questions
Do I need to know how to code to add login to my app?
Nope! That's what your AI tool is for. Just tell it which login provider you want (we recommend Clerk for beginners) and what kind of login you need (Google, email, etc.). It will write all the code for you.
Is Clerk free?
Yes, for most projects. Clerk's free plan covers up to 50,000 monthly retained users per app (people who come back at least a day after signing up). That's more than enough for personal projects, prototypes, and even small businesses. You only pay when you grow past that.
What's the difference between Clerk and Better Auth?
Clerk gives you beautiful, ready-made login screens that work out of the box (great for beginners). Better Auth is free and open source but requires more setup. It's also where NextAuth.js (Auth.js) went: the Auth.js team joined Better Auth in 2025 and recommends it for new projects. If you're just starting out, go with Clerk.
Can users log in with their Google account?
Absolutely! This is called "social login" or "OAuth." Most auth providers (Clerk, Better Auth, Supabase, Firebase) support Google, GitHub, Apple, and other social logins. Just tell your AI tool which ones you want.
What happens if I need to switch auth providers later?
It's possible but takes some work. That's why it's worth picking the right provider upfront. For most AI coders, Clerk is the easiest starting point. If you're already using Supabase for your database, Supabase Auth is a natural fit.
How do I make certain pages only visible to logged-in users?
Tell your AI tool something like: "Make the /dashboard page require login. If someone isn't signed in, redirect them to the sign-in page." Your AI tool will set up the protection for you.