(Next)Auth.js Drizzle Schema

See https://authjs.dev/getting-started/adapters/drizzle#schemas for the Drizzle Schema provided

I haven't been able to figure out how to get Auth.js schema working with drizzle. I believe the issue is handling the composite primary key

In the example, the accounts, verificationTokens, authenticators primaryKeys are respectively

  (account) => ({
    compoundKey: primaryKey({
      columns: [account.provider, account.providerAccountId],
    }),
  })

  (verificationToken) => ({
    compositePk: primaryKey({
      columns: [verificationToken.identifier, verificationToken.token],
    }),
  })

 (authenticator) => ({
    compositePK: primaryKey({
      columns: [authenticator.userId, authenticator.credentialID],
    }),
  })


Does the property name of the primary key matter? In my old drizzle schema, it looked like it was named compoundKey, while the current documentation uses either pk or pkWithCustomName and the auth.js example is compoundKey, compositePk, and compositePK (is this one a typo?).

I can run drizzle-kit generate and drizzle-kit migrate, while when running drizzle-kit push gives me this error:

[✓] Pulling schema from database...error: constraint "authenticator_userid_credentialid_pk" of relation "authenticator" does not exist
    at node_modules/.pnpm/drizzle-kit@0.22.5/node_modules/drizzle-kit/bin.cjs:77694:15 {
  length: 162,
  severity: 'ERROR',
  code: '42704',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'tablecmds.c',
  line: '11976',
  routine: 'ATExecDropConstraint'
}


Sorry if this doesn't make any sense, let me know if I can provide more information

Using node-postgress and pg driver, not sure if that matters
image.png
image.png
Authentication for the Web
Was this page helpful?