A minimal Next.js auth system using better-auth with email/password sign up and sign in.
- Email + password account creation
- Sign in and sign out
- Session-aware home page
- Protected
/dashboardpage (redirects if unauthenticated) - Next.js API route mounted at
/api/auth/*
- Install dependencies:
npm install- Create a
.env.localfile:
DATABASE_URL=postgres://USER:PASSWORD@HOST:5432/DB_NAME
BETTER_AUTH_SECRET=replace-with-a-long-random-secret
BETTER_AUTH_URL=http://localhost:3000- Start the dev server:
npm run dev- Open
http://localhost:3000.
- This project uses a PostgreSQL connection via
pg. - Make sure your database is reachable from the app.
- If you need migrations/seeding, run them per your better-auth setup.