This is a simple Next.js + TypeScript boilerplate app that uses Auth.js for authentication and session management. When a user logs in, their data is upserted to the PostgreSQL database with Auth.js's @auth/drizzle-adapter adapter.
The SQL models required by the AuthJS are available on Auth.js's database models documentation. This project uses @auth/drizzle-adapter so we can use their pre-defined Drizzle schema for PostgreSQL to generate the correct migrations with Drizzle.
This project uses Docker Compose for an easy dev setup, so you don't need to run a database natively. It will also automatically run the migrations for you when the Next.js server starts.
This project uses GitHub as the example OAuth provider. You can use any other OAuth provider by changing the configuration in auth.ts
.
Create a GitHub OAuth application with the callback URL of http://localhost:3000/api/auth/callback/github
.
Generate a random string for Auth.js to use to hash tokens, sign cookies and generate cryptographic keys.
openssl rand -hex 32
Now set the OAuth app's Client ID + Secret ID and Auth.js secret in the .env.local
file.
.env.local
is ignored by Git, so you can safely store secrets in it. Duplicate values in .env.local
will override those in .env
.
cp .env .env.local
vim .env.local
This will automatically install the NPM dependencies and run the DB migrations
docker compose up
Now visit http://localhost:3000 and login with GitHub! 🎉