nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.09k stars 3.33k forks source link

type error for Prisma Client with extensions #9413

Closed jeremy-code closed 7 months ago

jeremy-code commented 8 months ago

Adapter type

@auth/prisma-adapter

Environment

System: OS: macOS 14.2 CPU: (8) arm64 Apple M1 Memory: 101.66 MB / 8.00 GB Shell: 5.9 - /bin/zsh

Binaries: Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm

Browsers: Chrome: 120.0.6099.109 Safari: 17.2

npmPackages: @auth/prisma-adapter: ^1.0.11 => 1.0.11 next: 14.0.4 => 14.0.4 next-auth: ^4.24.5 => 4

Reproduction URL

https://github.com/jeremy-code/example-prisma-accelerate-adapter

Describe the issue

After extending a Prisma Client with Accelerate to use Prisma in edge environment, the Prisma Adapter throws an error, saying that the argument passed is not correct or 'PrismaClient<PrismaClientOptions, never, DefaultArgs>', and is missing the $on and $use properties.

Similar issue has been raised in prisma/prisma in issue: https://github.com/prisma/prisma/issues/22050: Type issues with prisma accelerate.

Issue occurs on both NextAuth.js v4 and Auth.js v5.

Error thrown is:

Argument of type 'DynamicClientExtensionThis<TypeMap<InternalArgs & { result: {}; model: { $allModels: { aggregate: () => <T, A>(this: T, args: Exact<A, Args<T, "aggregate"> & PrismaCacheStrategy>) => AcceleratePromise<...>; ... 6 more ...; groupBy: () => <T_7, A_7>(this: T_7, args: Exact<...>) => AcceleratePromise<...>; }; user: { ....' is not assignable to parameter of type 'PrismaClient<PrismaClientOptions, never, DefaultArgs>'.
  Type 'DynamicClientExtensionThis<TypeMap<InternalArgs & { result: {}; model: { $allModels: { aggregate: () => <T, A>(this: T, args: Exact<A, Args<T, "aggregate"> & PrismaCacheStrategy>) => AcceleratePromise<...>; ... 6 more ...; groupBy: () => <T_7, A_7>(this: T_7, args: Exact<...>) => AcceleratePromise<...>; }; user: { ....' is missing the following properties from type 'PrismaClient<PrismaClientOptions, never, DefaultArgs>': $on, $use

ts(2345)
image

How to reproduce

  1. Generate and instantiate a Prisma Client (as the default type is any) and extend it with Accelerate:
import { PrismaClient } from "@prisma/client/edge";
import { withAccelerate } from "@prisma/extension-accelerate";

const prisma = new PrismaClient().$extends(withAccelerate());
  1. Pass Prisma Client to PrismaAdapter, which results in TypeError

Expected behavior

No TypeError should have happened instead of what actually happened.

boredland commented 8 months ago

This seems to be a more general problem with extensions, not only with the Accelerate extension.