Auth.js and auth libraries
Choosing between hosted auth, self-run libraries and session toolkits, what happened to Auth.js, and how a library plugs into a Data Access Layer.
Auth.js and auth libraries
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Auth options fall into hosted identity services, libraries you run yourself, and session toolkits such as `iron-session` and `jose` that only manage the cookie.
- As of November 2026 `next-auth` latest is 4.24.15 with v5 still in beta, and the Auth.js README says it is part of Better Auth and recommends new projects start there.
- A library handles login and sessions, but deciding which user may open which record is still your code in the Data Access Layer.
- Put the library behind one `getCurrentUser()` function so changing libraries touches a single file.
Build it, or bring a library
The last two lessons showed what a correct auth system needs: a session cookie with the right flags, a Data Access Layer that verifies it, and authorization checks near the data. That is not much code, but it is code where small mistakes are security bugs, and the login side adds more: password hashing, rate limiting, email verification, password reset, OAuth flows with Google or GitHub, maybe passkeys. Few teams want to own all of it.
So the question is not “should I use a library” but “which kind”. The Next.js authentication guide lists a dozen, and they fall into three groups.
Three kinds of option
- Hosted identity services: Clerk, Auth0, Kinde, WorkOS, Supabase Auth and others. They run the login UI and user database for you and give you an SDK. Fastest to start, a vendor dependency, and usually a cost that grows with users.
- Libraries you run yourself: Better Auth, Auth.js (NextAuth), Stack Auth and similar. They live in your codebase and store users in your database. You keep control of the data and the bill.
- Session toolkits:
iron-sessionandjose. These handle only the cookie or token. You still write login, OAuth and everything else.
What happened to Auth.js
If you search for Next.js auth tutorials, most mention Auth.js, previously NextAuth.js, so its status matters. As of November 2026, npm view next-auth shows 4.24.15 as the stable release, with the v5 line (5.0.0-beta.32) still tagged beta, which is the version most recent tutorials teach. The project’s README now says Auth.js is part of Better Auth and recommends new projects start with Better Auth, with one stated gap: stateless session management without a database. That does not make existing Auth.js apps wrong. It does mean that for a new project you should read the current docs and make a deliberate choice rather than copying a 2024 tutorial.
What every library gives you in a Next.js app
The surface is similar across them, so learn the shape once.
A server-side instance with your config: providers, database adapter, session strategy. A route handler that the library owns, usually mounted at app/api/auth/[...all]/route.ts or similar, that handles the callbacks OAuth providers redirect to. A function to read the session on the server, which is what your DAL calls instead of decrypting a cookie itself. A client helper for sign-in buttons and for reading the session in Client Components.
Your DAL from the previous lesson barely changes. Where it called decrypt(cookie), it calls the library’s getSession(). Everything about where to check stays the same. A library handles login and sessions, but it does not decide which user may open which invoice. That is still your code.
Choosing, concretely
Ask four questions. Do you want to own user data? If not, a hosted service. Do you need a database anyway? If yes, a self-run library with a database adapter is natural. Do you need stateless sessions with no database? That is the Auth.js strength the README points at. And is the SDK actively maintained for your Next.js version? Check that it supports async cookies() and the Next.js 16 proxy.ts, since both changed.
Whatever you pick, put it behind a small seam, a getCurrentUser() function in your DAL, so changing libraries later touches one file.
What the video covers
Cosden Solutions’ “Better Auth in Next.js (Complete Tutorial)” is a 35-minute chaptered walkthrough from October 2025 that installs the library, sets environment variables, creates the server instance, connects a database, configures authentication, wires it into Next.js, writes sign-in Server Actions, builds the UI, and then explains the client instance. It is about Better Auth, not Auth.js, and it includes a sponsor break. It was picked because it is the most current end-to-end library integration I found for Next.js, and Better Auth is where the Auth.js maintainers point new projects. For Auth.js itself, two videos are listed under “deeper”: a 53-minute Auth.js v5 build with Prisma, OAuth and credentials, and a 21-minute video on the credentials provider. Those use the v5 beta APIs of 2024 and early 2025.
Where this fits
With sessions, checks, and a library, the app is identifying people correctly. The last piece is protecting the browser itself from hostile content. Next: security headers and CSP.
Check yourself
What are the three broad kinds of auth option for a Next.js app?
Hosted identity services that run login and users for you, libraries you run in your own codebase and database, and session toolkits that only manage the cookie or token.
What does a library change in a Data Access Layer you already wrote?
Only how the session is read, such as calling the library's `getSession()` instead of decrypting a cookie yourself; where checks happen stays the same.
What should you check before copying a 2024 Auth.js tutorial into a new project?
Whether Auth.js v5 is still beta, that the project now points new users to Better Auth, and that the library supports async `cookies()` and the Next.js 16 `proxy.ts`.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.