This repository combines Next.js and NextAuth.js with various authentication providers (Credentials, Facebook, Google) and session management for both App and Pages Routers.
Try demo https://next-auth-database-session-app.vercel.app/
- 🧙♂️ type safe with TypeScript
- ⚡ Full-stack React with Next.js (app/pages) routers
- ⚡ Database with Prisma
- ⚡ Monorepo with Turborepo
- 🔐 Authorization using next-auth (v4/v5)
- 🔐 Zod Validation
- 🎨 ESLint
Run the following command:
git clone https://github.com/decovicdev/next-auth-database-session.gitThis turborepo includes the following packages/apps:
app-dir-v4: a Next.js app (app directory) + NextAuth:v4app-dir-v5: a Next.js app (app directory) + NextAuth:v5pages-dir-v4: a Next.js app (pages directory) + NextAuth:v4config:eslintconfigurations (includeseslint-config-nextandeslint-config-prettier)validation:zodschemas to validate and parse user inputdatabase: Prisma ORM wrapper to manage & access your databasetsconfig:tsconfig.jsons used throughout the monorepo
Each package/app is 100% TypeScript.
This turborepo has some additional tools already setup for you:
- TypeScript for static type checking
- ESLint for code linting
- Prettier for code formatting
- Prisma for database ORM
- Docker Compose for local database
We use Prisma to manage & access our database. As such you will need a database for this project, either locally or hosted in the cloud.
To make this process easier, use docker-compose.yml file to deploy a PostgresSQL server locally with a new database named turborepo (To change this update the POSTGRES_DB environment variable in the docker-compose.yml file):
cd next-auth-database-session
docker-compose up -dOnce deployed you will need to copy the .env.example file to .env in order for Prisma to have a DATABASE_URL environment variable to access.
cp .env.example .envIf you added a custom database name, or use a cloud based database, you will need to update the DATABASE_URL in your .env accordingly.
Once deployed & up & running, you will need to create & deploy migrations to your database to add the necessary tables. This can be done using Prisma Migrate:
npx prisma migrate devIf you need to push any existing migrations to the database, you can use either the Prisma db push or the Prisma migrate deploy command(s):
pnpm run db:push
# OR
pnpm run db:migrate:deployFor further more information on migrations, seeding & more, we recommend reading through the Prisma Documentation.
To build all apps and packages, run the following command:
pnpm run buildTo develop all apps and packages, run the following command:
pnpm run devLearn more about the power of Turborepo: