Next.js Discord

Discord Forum

Next Auth + Prisma + Nextjs Error

Answered
European sprat posted this in #help-forum
Open in Discord
Avatar
European spratOP
prisma/schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

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

generator client {
  provider   = "prisma-client-js"
  engineType = "library"
}

model User {
  id            String    @id @default(cuid())
  name          String?
  email         String    @unique
  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])
}


src/middleware.ts
export { auth as middleware } from "@/auth";
Answered by European sprat
Soution is that I wasn't using accelerate properly
View full answer

5 Replies

Avatar
European spratOP
src/auth.ts
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { prisma } from "@/lib/prisma";

export const { handlers, signIn, signOut, auth } = NextAuth({
    adapter: PrismaAdapter(prisma),
    providers: [GitHub],
    pages: {
        signIn: "/auth/signin",
        signOut: "/auth/signout",
        error: "/auth/error", // Error code passed in query string as ?error=
        verifyRequest: "/auth/verify-request", // (used for check email message)
        newUser: "/auth/new-user", // New users will be directed here on first sign in (leave the property out if not of interest)
    },
    callbacks: {
        async signIn({ user, account, profile, email, credentials }) {
            return true;
        },
        async redirect({ url, baseUrl }) {
            return baseUrl;
        },
        async session({ session, user, token }) {
            return session;
        },
        async jwt({ token, user, account, profile, isNewUser }) {
            return token;
        },
    },
});


src/lib/prisma.ts
```ts
import { PrismaClient } from "@prisma/client/edge";

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };

export const prisma = globalForPrisma.prisma || new PrismaClient();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
Error:
Error [PrismaClientValidationError]: Invalid client engine type, please use `library` or `binary`
    at <unknown> (webpack-internal:///(middleware)/./node_modules/@prisma/client/runtime/edge.js:29)
    at us (webpack-internal:///(middleware)/./node_modules/@prisma/client/runtime/edge.js:12:65)
    at new t (webpack-internal:///(middleware)/./node_modules/@prisma/client/runtime/edge.js:29:3661)
    at eval (webpack-internal:///(middleware)/./src/lib/prisma.ts:9:42)
    at (middleware)/./src/lib/prisma.ts (file:///Users/user/Documents/Projects/GitHub/pyhost/.next/server/src/middleware.js:915:1)
    at __webpack_require__ (file:///Users/user/Documents/Projects/GitHub/pyhost/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/user/Documents/Projects/GitHub/pyhost/.next/server/edge-runtime-webpack.js:285:21)
    at eval (webpack-internal:///(middleware)/./src/auth.ts:11:69)
    at (middleware)/./src/auth.ts (file:///Users/user/Documents/Projects/GitHub/pyhost/.next/server/src/middleware.js:904:1)
    at __webpack_require__ (file:///Users/user/Documents/Projects/GitHub/pyhost/.next/server/edge-runtime-webpack.js:37:33)
    at fn (file:///Users/user/Documents/Projects/GitHub/pyhost/.next/server/edge-runtime-webpack.js:285:21)
package.json
{
    "name": "pyhost",
    "version": "0.1.0",
    "private": true,
    "scripts": {
        "dev": "next dev",
        "build": "next build",
        "start": "next start",
        "lint": "next lint",
        "postinstall": "prisma generate --no-engine"
    },
    "dependencies": {
        "@auth/prisma-adapter": "^2.4.2",
        "@prisma/client": "^5.9.1",
        "@radix-ui/react-icons": "^1.3.0",
        "class-variance-authority": "^0.7.0",
        "clsx": "^2.1.1",
        "lucide-react": "^0.438.0",
        "next": "14.2.7",
        "next-auth": "^5.0.0-beta.20",
        "react": "^18",
        "react-dom": "^18",
        "tailwind-merge": "^2.5.2",
        "tailwindcss-animate": "^1.0.7"
    },
    "devDependencies": {
        "@types/node": "^20",
        "@types/react": "^18",
        "@types/react-dom": "^18",
        "eslint": "^8",
        "eslint-config-next": "14.2.7",
        "postcss": "^8",
        "prisma": "^5.9.1",
        "tailwindcss": "^3.4.1",
        "typescript": "^5"
    }
}
Avatar
it would be better to directly describe ur error without sending a ton of text
Avatar
European spratOP
Soution is that I wasn't using accelerate properly
Answer