AUTHENTICATION / LESSON 05
Better Auth Basics.
What Better Auth is and how a self run auth library differs from a hosted service like Clerk

Loading the lesson…
Loading activities…
AUTHENTICATION / LESSON 05
What Better Auth is and how a self run auth library differs from a hosted service like Clerk

Loading the lesson…
Loading activities…
In the last few lessons you met Clerk, a service that runs login for you on its own servers. Better Auth solves the same problem from the other direction. It's code you add to your own app, and it keeps your users in your OWN database.
Better Auth describes itself as a "framework-agnostic, universal authentication and authorization framework for TypeScript." Big mouthful. Let's chew on it one piece at a time.
The word that matters most in this lesson is library. You won't find a Better Auth website to sign up for, because it's a package of code that runs inside your app.
Think of it like cooking at home versus ordering takeout.
With a hosted service like Clerk, somebody else runs the kitchen. You connect your app to their servers, and they store your users, check passwords and manage sessions. You get a dashboard for changing settings.
With a library like Better Auth, YOU run the kitchen. The auth code lives in your project. When someone signs up, your own server checks their details and saves them to your own database.
Here's how they stack up side by side.
| Question | Better Auth | Clerk |
|---|---|---|
| What is it? | A library you install in your app | A hosted service you connect to |
| Where do user records live? | In your own database | On the service's servers |
| Who runs the auth code? | Your server | The service |
| Where do you change settings? | In your code, in a file called auth.ts | Mostly in a web dashboard |
This is the BIG difference between the two.
The Better Auth docs say it "connects to a database to store data" such as "users, sessions, and more." That database is yours. It could be PostgreSQL, MySQL or SQLite, or a database you reach through a tool like Prisma or Drizzle.
When you connect a database, Better Auth needs a few tables in it. The docs call this the core schema, and it's four tables.
user holds each person's accountsession keeps track of who's logged inaccount stores each way a user can log in, like a password or a GitHub accountverification holds verification recordsOn its comparison page, Better Auth lists "Keep your data" as a reason to pick it over managed services, saying "Users stay in your database, not a third-party service."
I'll be honest, this is the part that gets me excited. My whole thing is own your tools, don't rent them. When the software you depend on belongs to somebody else, they can change the rules any Monday they feel like it... and you just find out.
With Better Auth, you run it. It runs as part of your app, on whatever server or host your app already uses. That same comparison page says you can "Run alongside your app or as a standalone self-hosted auth server" if you'd rather keep auth on its own.
So what does it cost? Here's what the official sources say.
Free library doesn't mean free auth though. You still pay for your own hosting and your own database, just like the rest of your app. For Clerk's prices, check the Clerk pricing page, since those move around.
Out of the box, the docs say Better Auth has built-in support for two ways to sign in.
Everything else gets added through plugins. A plugin is an extra piece you switch on in your config. The docs mention plugins for stuff like this.
The docs also list bigger features like multi-tenancy, multi-session support, rate limiting and enterprise single sign-on (SSO).
Both are solid picks. They just fit different situations.
Clerk might fit better when
Better Auth might fit better when
Here's a simple way to think about it. Clerk trades some control for convenience. Better Auth trades some convenience for control.
Next up, you'll install Better Auth step by step. You'll set up the secret key, create the auth file, hook up a database and run the CLI that creates the tables...