0
Challenge · 30Mutations & Auth

Auth with Better Auth

Securityused in ~88% of apps

Half the auth tutorials you will find this year are quietly wrong: they reach for NextAuth/Auth.js, which went maintenance-only in September 2025. Worse, they read the session with a synchronous cookies() call that throws in Next.js 16. Get this concept right and you own your users, your sessions, and a login flow that actually compiles.

Core idea. Use Better Auth: it owns a real users + sessions table in YOUR Postgres (via the Prisma adapter), sets an httpOnly session cookie, and you read the current user on the server with `await auth.api.getSession({ headers: await headers() })` — note both `headers()` and `cookies()` are async in Next.js 16.
Playground, this isn't a screenshot
where does the token live?
Browser (client)

Guest

no credentials

cookie jar
empty
Server (the real lock)

Verifies the password, signs the token with a secret only it holds, and re-checks the token on every request.

POST /login
-> verify password
-> sign JWT, return
You are a guest — no token yet. Pick where the token will live, then log in.
HttpOnly = JS can't read it localStorage = any script can read it
↑ play a little first, then dig in