Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Error or bug using Prisma with DriverAdapter with PostgreSQL database Neon #23903

Open
EddyerDevv opened this issue Apr 19, 2024 · 6 comments
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: async/await topic: database-provider/neon https://neon.tech/ topic: driverAdapters topic: Next.js topic: next-auth / Auth.js

Comments

@EddyerDevv
Copy link

EddyerDevv commented Apr 19, 2024

Bug description

I'm using NextJS and NextAuth in its v5 beta version, when I use Prisma with Neon as a postgresql database, and using the adapters, to remove the Edge Functions error, I get that, and it is a basic code, what can be the solution, or is it a bug?

Error

image

Code

image

How to reproduce

The error or bug occurs when it is already running, it appears for a few moments or several logs and then does not appear.

Expected behavior

No response

Prisma information

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["driverAdapters"]
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String    @unique
  role          UserRole  @default(USER)
  emailVerified DateTime?
  image         String?
  accounts      Account[]
  sessions      Session[]

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model Account {
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?
  access_token      String?
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?
  session_state     String?

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@id([provider, providerAccountId])
}

model Session {
  sessionToken String   @unique
  userId       String
  expires      DateTime
  user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

model VerificationToken {
  identifier String
  token      String
  expires    DateTime

  @@id([identifier, token])
}

enum UserRole {
  USER
  ADMIN
}

Environment & setup

  • OS: Windows 11
  • Database: PostgreSQL
  • Node.js version: 20.12.2

Prisma Version

Prisma Version:  5.12.1
@EddyerDevv EddyerDevv added the kind/bug A reported bug. label Apr 19, 2024
@Jes015
Copy link

Jes015 commented Apr 19, 2024

Interesting

@janpio janpio added topic: Next.js team/client Issue for team Client. topic: driverAdapters bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Apr 23, 2024
@janpio
Copy link
Member

janpio commented Apr 23, 2024

Does this cause any problems or error, or is this just a warning?

@EddyerDevv
Copy link
Author

It is a warn, but at the end of so many calls or restarts of the page, sometimes it does not restart and I have to restart the server, already in turbo mode because the warn does not appear.

@Hugo-Lorenzoni
Copy link

Hugo-Lorenzoni commented May 1, 2024

Same here !

Initially I had this problem :

[auth][error] AdapterError: Read more at https://errors.authjs.dev#adaptererror
[auth][cause]: Error: PrismaClient is not configured to run in Vercel Edge Functions or Edge Middleware. In order to run Prisma Client on edge runtime, either:

If this is unexpected, please open an issue: https://pris.ly/prisma-prisma-bug-report
at Object.get (webpack-internal:///(middleware)/./node_modules/.prisma/client/index-browser.js:207:15)
at getSessionAndUser (webpack-internal:///(middleware)/./node_modules/@auth/prisma-adapter/index.js:240:44)
at acc. (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/init.js:178:30)
at Module.session (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/actions/session.js:67:36)
at AuthInternal (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/index.js:47:77)
at async Auth (webpack-internal:///(middleware)/./node_modules/@auth/core/index.js:126:34)
at async handleAuth (webpack-internal:///(middleware)/./node_modules/next-auth/lib/index.js:134:29)
at async adapter (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/adapter.js:179:16)
at async C:\Code\iot-project\node_modules\next\dist\server\web\sandbox\sandbox.js:110:22
at async runWithTaggedErrors (C:\Code\iot-project\node_modules\next\dist\server\web\sandbox\sandbox.js:107:9)
[auth][details]: {}
[auth][error] SessionTokenError: Read more at https://errors.authjs.dev#sessiontokenerror
[auth][cause]: Error: PrismaClient is not configured to run in Vercel Edge Functions or Edge Middleware. In order to run Prisma Client on edge runtime, either:

If this is unexpected, please open an issue: https://pris.ly/prisma-prisma-bug-report
at Object.get (webpack-internal:///(middleware)/./node_modules/.prisma/client/index-browser.js:207:15)
at getSessionAndUser (webpack-internal:///(middleware)/./node_modules/@auth/prisma-adapter/index.js:240:44)
at acc. (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/init.js:178:30)
at Module.session (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/actions/session.js:67:36)
at AuthInternal (webpack-internal:///(middleware)/./node_modules/@auth/core/lib/index.js:47:77)
at async Auth (webpack-internal:///(middleware)/./node_modules/@auth/core/index.js:126:34)
at async handleAuth (webpack-internal:///(middleware)/./node_modules/next-auth/lib/index.js:134:29)
at async adapter (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/adapter.js:179:16)
at async C:\Code\iot-project\node_modules\next\dist\server\web\sandbox\sandbox.js:110:22
at async runWithTaggedErrors (C:\Code\iot-project\node_modules\next\dist\server\web\sandbox\sandbox.js:107:9)
[auth][details]: {}

I don't know why because I never tried to use the edge.

So then, i tried to use the neon edge adapter and got the same error as you...

@Hugo-Lorenzoni
Copy link

I just found out something !
I downgraded next-auth to version 4.24.3 and I have the same error message than the one I posted to abose when I try to use the Nextjs Middleware.
So the problem might come from the fact that the middleware is suppose to run on the edge or something like that and that the prisma adapter is not made for that !

Middleware

import { withAuth } from "next-auth/middleware";
import prisma from "./db";

export default withAuth(
  // `withAuth` augments your `Request` with the user's token.
  function middleware(req) {
    console.log(req.nextauth.token);
  },
  {
    callbacks: {
      authorized: async ({ req: { cookies } }) => {
        const sessionToken = cookies.get("next-auth.session-token")?.value;
        const user = await prisma.session
          .findUnique({ where: { sessionToken } })
          .user();
        console.log(user?.isAdmin);

        return sessionToken != null;
      },
    },
  }
);

Error

⨯ Error: PrismaClient is not configured to run in Vercel Edge Functions or Edge Middleware. In order to run Prisma Client on edge runtime, either:

If this is unexpected, please open an issue: https://pris.ly/prisma-prisma-bug-report
at Object.get (webpack-internal:///(middleware)/./node_modules/.prisma/client/index-browser.js:207:15)
at Object.authorized (webpack-internal:///(middleware)/./src/middleware.ts:18:76)
at handleMiddleware (webpack-internal:///(middleware)/./node_modules/next-auth/next/middleware.js:50:334)
at async Object.options [as handler] (webpack-internal:///(middleware)/./node_modules/next-auth/next/middleware.js:68:31)
at async adapter (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/adapter.js:179:16)
at async (file://C:\Code\iot-project\node_modules\next\dist\server\web\sandbox\sandbox.js:110:22)
at async runWithTaggedErrors (file://C:\Code\iot-project\node_modules\next\dist\server\web\sandbox\sandbox.js:107:9)
at async DevServer.runMiddleware (file://C:\Code\iot-project\node_modules\next\dist\server\next-server.js:1062:24)
at async DevServer.runMiddleware (file://C:\Code\iot-project\node_modules\next\dist\server\dev\next-dev-server.js:268:28)
at async NextNodeServer.handleCatchallMiddlewareRequest (file://C:\Code\iot-project\node_modules\next\dist\server\next-server.js:324:26)

@EddyerDevv
Copy link
Author

@Hugo-Lorenzoni Well, if you are using neon serverless it works, everything and remove the prism warn from the edge functions, and that works but sometimes the Edge Functions invocations are not completed because of the async await, in the middleware it can serve as protecting routes, I I solved it by removing the middleware, since I won't need it for the moment, but I think it's a Prisma adapter error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: async/await topic: database-provider/neon https://neon.tech/ topic: driverAdapters topic: Next.js topic: next-auth / Auth.js
Projects
None yet
Development

No branches or pull requests

6 participants