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

Drizzle Adapter Postgres Broken – The types of _.config.columns.id are incompatible between these types. #11490

Open
FroeMic opened this issue Jul 31, 2024 · 4 comments
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@FroeMic
Copy link

FroeMic commented Jul 31, 2024

Adapter type

@auth/drizzle-adapter

Environment

  System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M2 Max
    Memory: 3.54 GB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 10.2.1 - ~/.nvm/versions/node/v18.17.1/bin/npm
    pnpm: 8.10.5 - ~/Library/pnpm/pnpm
  Browsers:
    Brave Browser: 126.1.67.119
    Chrome: 127.0.6533.73
    Safari: 17.5
  npmPackages:
    @auth/drizzle-adapter: ^1.1.0 => 1.4.2 
    next: ^14.2.4 => 14.2.5 
    next-auth: ^4.24.7 => 4.24.7 
    react: ^18.3.1 => 18.3.1 

Reproduction URL

https://github.com/FroeMic/t3-auth-test

Describe the issue

After running npm create t3-app@latest the NextAuth DrizzleAdapter throws a Typescript error in /src/server/auth.ts (see reproduction example.

It seems that the schemas generated by drizzle are not compatible with the ones the adapter expects. Some properties expected by the column type of the adapter are not provided by the schemas generated by drizzle.

Using the first example from the PostgreSQL schema.ts example from https://authjs.dev/getting-started/adapters/drizzle#schemas:

Schema

export const users = pgTable("user", {
  id: text("id")
    .primaryKey()
    .$defaultFn(() => crypto.randomUUID()),
  name: text("name"),
  email: text("email").unique(),
  emailVerified: timestamp("emailVerified", { mode: "date" }),
  image: text("image"),
})

Typescript Error (formatted)

Type 'PgTableWithColumns<{ 
  name: "user"; 
  schema: undefined; 
  columns: { 
    id: PgColumn<{ 
      name: "id"; 
      tableName: "user"; 
      dataType: "string"; 
      columnType: "PgText"; 
      data: string; 
      driverParam: string; 
      notNull: true; 
      hasDefault: true; 
      enumValues: [...]; 
      baseColumn: never; 
    }, {}, {}>; 
    name: PgColumn<...>; 
    email: PgColumn<...>; 
    ema... 
  } 
}>' is not assignable to type 'DefaultPostgresUsersTable'.

Type 'PgTableWithColumns<{ 
  name: "user"; 
  schema: undefined; 
  columns: { 
    id: PgColumn<{ 
      name: "id"; 
      tableName: "user"; 
      dataType: "string"; 
      columnType: "PgText"; 
      data: string; 
      driverParam: string; 
      notNull: true; 
      hasDefault: true; 
      enumValues: [...]; 
      baseColumn: never; 
    }, {}, {}>; 
    name: PgColumn<...>; 
    email: PgColumn<...>; 
    ema... 
  } 
}>' is not assignable to type 'PgTable<{ 
  name: string; 
  columns: { 
    id: DefaultPostgresColumn<{ 
      columnType: "PgVarchar" | "PgText" | "PgUUID"; 
      isPrimaryKey: true; 
      data: string; 
      notNull: true; 
      dataType: "string"; 
    }>; 
    name: DefaultPostgresColumn<...>; 
    email: DefaultPostgresColumn<...>; 
    emailVerified: DefaultPostgresColumn<...>; 
    image: DefaultPostgres... 
  }>'.

  The types of '_.config.columns.id' are incompatible between these types.

  Type 'PgColumn<{ 
    name: "id"; 
    tableName: "user"; 
    dataType: "string"; 
    columnType: "PgText"; 
    data: string; 
    driverParam: string; 
    notNull: true; 
    hasDefault: true; 
    enumValues: [string, ...string[]]; 
    baseColumn: never; 
  }, {}, {}>' is not assignable to type 'DefaultPostgresColumn<{ 
    columnType: "PgVarchar" | "PgText" | "PgUUID"; 
    isPrimaryKey: true; 
    data: string; 
    notNull: true; 
    dataType: "string"; 
  }>'.

  Type '{ 
    name: "id"; 
    tableName: "user"; 
    dataType: "string"; 
    columnType: "PgText"; 
    data: string; 
    driverParam: string; 
    notNull: true; 
    hasDefault: true; 
    enumValues: [string, ...string[]]; 
    baseColumn: never; 
  }' is missing the following properties from type '{ 
    name: string; 
    isAutoincrement: boolean; 
    isPrimaryKey: true; 
    hasRuntimeDefault: boolean; 
    generated: any; 
    columnType: "PgVarchar" | "PgText" | "PgUUID"; 
    data: string; 
    driverParam: string | number | boolean; 
    ... 4 more ...; 
    tableName: string; 
  }': 
    isAutoincrement, 
    isPrimaryKey, 
    hasRuntimeDefault, 
    generated

What does that mean? The DefaultPostgresColumn type definition in adapter-drizzle/src/lib/pg.ts expects for each column values (isAutoincrement, isPrimaryKey, hasRuntimeDefault, generated), that the schema generated by pgTable doesn't have.

How to reproduce

You should be able to reproduce the error by running npm create t3-app@latest with the above mentioned options and then opening /src/server/auth.ts and /src/server/db/schema.ts

  • TypeScript
  • Tailwind
  • tRCP
  • NextAuth.js
  • Drizzle
  • App Router
  • PosgreSQL
  • Git (yes)
  • npm install (yes)
  • alias: ~/

Expected behavior

The Table / Column Definitions generated by Drizzle are compatible with the Adapter.

@FroeMic FroeMic added adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Jul 31, 2024
@dca123
Copy link

dca123 commented Aug 1, 2024

I've temporarily resolved by using the previous patch "@auth/drizzle-adapter": "1.4.1"

@nathanredblur
Copy link

nathanredblur commented Aug 12, 2024

The hard part was to figure out how to ask about this issue in google.
here a more detailed error description.

@eaoliver
Copy link

eaoliver commented Aug 18, 2024

I had a similar issue, migrated back to 1.4.1. It went away when I upgraded drizzle-orm to version 0.33.0.

@Q16solver
Copy link

Q16solver commented Sep 8, 2024

It also seems like the authenticators table doesn't include the PgUuid type for user id when it's a uuid, so an incompatibility there as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapters Changes related to the core code concerning database adapters bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

5 participants