Next.js Discord

Discord Forum

Type Mismatch On Prisma Next Auth Adapter

Answered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
I am getting a type mismatch when I am trying to pass in the Prisma Adapter. Here is the Type error i am seeing:

Type 'import("../node_modules/@auth/core/adapters").Adapter' is not assignable to type 'import("../node_modules/next-auth/adapters").Adapter'.
  Type 'Adapter' is not assignable to type 'DefaultAdapter & { createVerificationToken: (verificationToken: VerificationToken) => Awaitable<VerificationToken>; useVerificationToken: (params: { ...; }) => Awaitable<...>; }'.
    Type 'Adapter' is not assignable to type 'DefaultAdapter'.
      Property 'createUser' is optional in type 'Adapter' but required in type 'DefaultAdapter'.ts(2322)
types.d.ts(106, 5): The expected type comes from property 'adapter' which is declared here on type 'AuthOptions'

I am using:
"@auth/prisma-adapter": "^1.0.0",
"@prisma/client": "^4.16.1",
"next-auth": "^4.22.1",

Following these docs with a monorepo implementation:
https://authjs.dev/reference/adapter/prisma

Anyone experience this type issue before?

Follow up: Code runs, and the adapter works fine -- but just this pesky type error.
Answered by Sloth bear
The issue is exactly as stated. The types between the two libraries are incompatible, and the optional fields mess with the required expected fields in Next Auth.

Work Around: Casting as Adapter from next auth library fixes the issue and the code works.

There should be a fix for this to make the Prisma Adapter compatible with the current version of next-auth.
View full answer

2 Replies

Sloth bearOP
import { Adapter } from "next-auth/adapters";
const handler = NextAuth({
  adapter: PrismaAdapter(prisma) as Adapter,
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    }),
  ],
});

This gets rid of it, but still wondering why it just doesn't work out of the box. Did some digging and it looks like prisma under its Adapter type has the fields as optional, while under next-auth, their adapter type has them as required. Could this be causing the issue?
Sloth bearOP
The issue is exactly as stated. The types between the two libraries are incompatible, and the optional fields mess with the required expected fields in Next Auth.

Work Around: Casting as Adapter from next auth library fixes the issue and the code works.

There should be a fix for this to make the Prisma Adapter compatible with the current version of next-auth.
Answer