ndom91 / authjs-prisma-edge-example

Example project for Auth.js with Prisma's Edge runtime support

Home Page:https://authjs-prisma-edge-example.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Auth.js + Prisma Edge Example App

Open Source. Full Stack. Own Your Data.

npm Bundle Size TypeScript

🧭 Overview

This is an example application showing Auth.js (next-auth@5.0.0-beta.15) and Prisma (@prisma/client@5.12.0) working together in edge runtimes, like Vercel's middleware or Cloudflare Workers.

This had previously only been possible with significant workarounds and limitations. As of @prisma/client@5.9.1 Prisma began making changes to their client, for example, to error out at query-time, not instantiation. So you could begin using Prisma with next-auth in Edge runtimes, as long as you didn't actually execute any queries on the edge. This implied using the Auth.js setting session: { strategy: 'jwt' }, as the strategy: 'database' didn't work because we couldn't update the expiry time of a database-based session in the middleware handler.

Prisma has now rolled out edge-compatible clients and adapters which communicate via HTTP, making them much more straightforward to run under any JavaScript runtime. You can check out their edge deployment page for a current list of supported adapters and platforms.

As this example shows, however, using Prisma + Auth.js with an Edge-compatible database provider and adapter like Neon (Vercel Postgres), PlanetScale or Turso is beginning to become much more straightforward!

πŸš€ Getting Started

1. Clone the repository and install dependencies

git clone https://github.com/ndom91/authjs-prisma-edge-example.git
cd authjs-prisma-edge-example
pnpm install

2. Configure your local environment

Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):

cp .env.example .env

Make sure to fill out the AUTH_SECRET env var as well as your Prisma database connection string(s). Also, don't forget to add environment variables to configure any of the supported providers for Auth.js login.

3. Database

This example is configured to use a Neon Postgres database (Vercel Postgres also works). Any Prisma Edge compatible database driver should work with a bit of tweaking though, these currently include:

  • PlanetScale serverless driver with @prisma/adapter-planetscale
  • Neon serverless driver with @prisma/adapter-neon
  • Turso with @prisma/adapter-libsql
  • Cloudflare D1 with @prisma/adapter-d1
  • PostgreSQL with @prisma/adapter-pg

See Prisma's Edge compatible driver documentation for more details.

4. Start the application

To run your site locally, use:

pnpm dev

πŸ“ License

MIT

About

Example project for Auth.js with Prisma's Edge runtime support

https://authjs-prisma-edge-example.vercel.app


Languages

Language:TypeScript 88.6%Language:JavaScript 6.9%Language:CSS 4.5%