A step-by-step guide to building email/password authentication with session management using Better Auth, Next.js, Drizzle ORM, and SQLite. Covers project setup, database schema definition (user, session, account, verification tables), Better Auth configuration, sign-up/sign-in form components, session handling with the useSession hook, and securing routes via both client-side redirects and Next.js middleware. Also explains how Better Auth compares to alternatives like NextAuth, Clerk, Auth0, and Passport.js.
Table of contents
PrerequisitesWhat Is Better Auth?Project SetupDatabase SetupSyncing DatabaseAPI RouteAuth ClientEmail and Password AuthenticationSign-in FormCreating Authentication PagesAccessing User SessionsSession Management and Protected RoutesProtecting Routes with MiddlewareRefactor the DashboardConclusionSort: