Code Monkey home page Code Monkey logo

next-auth-drizzle-starter's Introduction

Next.js + Auth.js + Drizzle + Docker starter

Introduction

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.

Getting Started

Setup OAuth provider(s)

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 an Auth.js secret

Generate a random string for Auth.js to use to hash tokens, sign cookies and generate cryptographic keys.

openssl rand -hex 32

Configure the environment

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

Run the development stack

This will automatically install the NPM dependencies and run the DB migrations

docker compose up

Now visit http://localhost:3000 and login with GitHub! ๐ŸŽ‰

next-auth-drizzle-starter's People

Contributors

dependabot[bot] avatar tobyscott25 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.