nextauthjs / next-auth

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

@auth/drizzle-adapter incompatibility - linkAccount #8283

Closed thepeterkovacs closed 1 year ago

thepeterkovacs commented 1 year ago

Question 💬

While using the latest version of next-auth (4.22.5) and @auth/drizzle-adapter (0.2.1), the following error occurred in the NextAuthOptions:

Types of property 'linkAccount' are incompatible.

I've set up the minimum required adapter in Postgres according to the documentation.

Here is my code:

import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { SqlFlavorOptions } from "@auth/drizzle-adapter/lib/utils"
import { NextAuthOptions } from "next-auth"
import GithubProvider from "next-auth/providers/github"

import { db } from "@/database/supabase/connection"
import { pgTable } from "@/database/supabase/schema"

export const options: NextAuthOptions = {
        /* the error occurs here */
    adapter: DrizzleAdapter(db as SqlFlavorOptions, pgTable),
    providers: [
        GithubProvider({
            clientId: process.env.GITHUB_CLIENT_ID,
            clientSecret: process.env.GITHUB_CLIENT_SECRET,
        }),
...

Any idea how to resolve this issue? Thanks in advance!

How to reproduce ☕️

Follow the documentation for setting up the drizzle adapter with Postgres: https://authjs.dev/reference/adapter/drizzle#drizzleadapter

Contributing 🙌🏽

Yes, I am willing to help answer this question in a PR

SSardorf commented 1 year ago

I outline the issue here, if anyone wants to fix: https://github.com/nextauthjs/next-auth/issues/8280#issuecomment-1672940275

balazsorban44 commented 1 year ago

I released a fix in @auth/core, which is a transient dependency of @auth/*-adapter. For it to take effect, you might need to delete node_modules/lock file and reinstall packages.

It's included in @auth/core@0.10.4

If that doesn't work, you can check your package manager's override config, eg. for pnpm adding the following to your package.json should fix the issue:

  "pnpm": {
    "overrides": {
      "@auth/core": "^0.10.4"
    }
  }
SnekCode commented 1 year ago

I released a fix in @auth/core, which is a transient dependency of @auth/*-adapter. For it to take effect, you might need to delete node_modules/lock file and reinstall packages.

It's included in @auth/core@0.10.4

If that doesn't work, you can check your package manager's override config, eg. for pnpm adding the following to your package.json should fix the issue:

  "pnpm": {
    "overrides": {
      "@auth/core": "^0.10.4"
    }
  }

Hello, I'm still experiencing this problem even after installing latest version of auth/core. Attempted doing what you mentioned above with no luck.

I'm implementing a custom adapter where I have imported the types from @auth/adapters. I receive typescript errors when I pass the custom adapter via NextAuthOptions. same errors as above with some others Types of property 'linkAccount' are incompatible.

I really wish next-auth would export their adapter types that would make all of this much easier.

VV made some progress VV

Edit: I was able to side step the type error by defining the type of Adapter as type Adapter = NextAuthOptions['adapter']. This works becuase I'm not using the Adapter type from @auth/core. So I still think there might be a problem here.

Edit 2: @balazsorban44 just saw your comment on this issue so sorry for the extra noise https://github.com/nextauthjs/next-auth/issues/8280#issuecomment-1672940275

balazsorban44 commented 1 year ago

If you are importing types from @auth/core/adapters, make sure it's at least the above mentioned version. Otherwise you can keep using next-auth/adapters for your custom one.

Here is the explanation https://github.com/nextauthjs/next-auth/pull/8294

SnekCode commented 1 year ago

Yup, was using "@auth/core": "^0.11.1",

I don't have an export from next-auth/adapters when using "next-auth": "^4.23.0",

image

balazsorban44 commented 1 year ago

Fixed via https://github.com/nextauthjs/next-auth/commit/20c3fe3331273893651c68d2e43151b4ca0c67b4, will release later. 🙏