Giter VIP home page Giter VIP logo

authjs-prisma-edge-example's Introduction


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 ([email protected]) and Prisma (@prisma/[email protected]) 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/[email protected] 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

authjs-prisma-edge-example's People

Contributors

ndom91 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.