Authentication & Login for AI Coders | SheCodes
Intermediate 7 min read

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

Protect User Data Keep personal information, passwords, and payment details safe from unauthorized access.
Personalize Experiences Show each user their own dashboard, settings, saved items, and preferences.
Control Access Restrict pages and features to logged-in users, admins, or specific roles.

Auth Providers Compared

Clerk Recommended Drop-in authentication components with a beautiful UI. Handles sign-in, sign-up, user profiles, and multi-factor auth out of the box. Pros
  • Easiest setup: add components and it works
  • Beautiful pre-built UI (SignIn, SignUp, UserButton)
  • Generous free tier (50,000 monthly retained users per app)
Cons
  • Paid plans can get expensive at scale
  • Less control over the auth UI
Best for: Beginners & fast prototyping
Better Auth Open-source authentication library for TypeScript apps, including Next.js. It now also maintains Auth.js (formerly NextAuth.js) and is the recommended choice for new projects that want to own their login. Pros
  • Completely free and open source
  • Supports Google, GitHub, Apple and many more login services
  • Full control over database and session handling
Cons
  • More setup and configuration required (your AI tool can help)
Best for: Developers who want full control
Supabase Auth Authentication built into the Supabase platform. Email/password, magic links, and social logins with controls for who can see what data. Pros
  • Integrated with Supabase database and storage
  • Controls who can see what data for fine-grained access
  • Magic link (passwordless) login built in
Cons
  • Tied to the Supabase ecosystem
  • UI components are more basic
Best for: Projects already using Supabase
Firebase Auth Google's authentication service. Supports email, phone, Google, Facebook, Apple, and more. Great ready-made tools for web and mobile. Pros
  • Excellent mobile support (iOS, Android, Flutter)
  • Phone number authentication built in
  • Backed by Google infrastructure
Cons
  • Tied to the Firebase/Google ecosystem
  • Can be complex to set up with Next.js
Best for: Apps that also need mobile support

What Auth Screens Look Like

Visual mockups of the most common authentication UI patterns you'll build.

Login Form

Welcome back

Sign in to your account

Email address
Password
Forgot password?
Sign In
or continue with
Google
GitHub

Don't have an account? Sign up

Sign Up Form

Create an account

Get started for free

Full name
Email address
Password
Password strengthStrong
I agree to the Terms of Service and Privacy Policy
Create Account
Social Login Buttons Standard OAuth button patterns. Learn more in our social login guide.
Continue with Google
Continue with GitHub
Continue with Apple
or
Email address
Continue with Email
User Profile Dropdown

Logged-in user menu pattern

JD

Jane Doe

jane@example.com

Profile
Settings
Billing
Sign out

Key Concepts

Session vs JWT A session stores your login info on the server, like a hotel keycard that the front desk keeps track of. A JWT stores it in a token your browser holds, like a stamped hand at a concert. Both prove you're logged in, just in different ways.
OAuth (Login with Google/GitHub) Let users sign in with their Google or GitHub account instead of creating a new password. Your app never sees their password: Google or GitHub confirms who they are and sends the info back to your app.
Pages That Require Login Some pages should only be visible to logged-in users. If someone who isn't signed in tries to visit those pages, they get sent to the login page instead. Common examples: dashboard, settings, profile, billing.
Roles & Permissions Not all logged-in users should see everything. Roles (admin, editor, viewer) control what each user can do. Permissions are the specific actions a role allows (create, read, update, delete).

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. 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. 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. 3
    Tell your AI tool to set up Clerk
    Tell 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. 4
    Ask your AI tool to protect pages
    Tell 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. 5
    Add a user menu to your navigation
    Tell 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

Login Page Email/password form with social login buttons (Google, GitHub). Include 'Forgot password' link and 'Sign up' redirect.
Sign Up Page Name, email, password fields with validation. Password strength indicator. Terms of service checkbox. Email verification.
Protected Dashboard Redirect unauthenticated users to login. Show user-specific data, settings, and navigation only when logged in.
User Profile Menu Avatar/initials button in the navbar that opens a dropdown with profile, settings, and sign out options.
Role-Based Access Show or hide UI elements based on user role. Admins see an admin panel. Editors can edit content. Viewers can only read.

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 AUTH WITH CLERK

“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 PAGES

“Protect my [dashboard/settings/admin] pages so only logged-in users can access them. Redirect unauthenticated users to the login page.”

ADD ROLE-BASED ACCESS

“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.