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

DrizzleKit Adapter not respecting $defaultFn for user.id #10859

Open
SlavenIvanov opened this issue May 9, 2024 · 0 comments
Open

DrizzleKit Adapter not respecting $defaultFn for user.id #10859

SlavenIvanov opened this issue May 9, 2024 · 0 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

@SlavenIvanov
Copy link

Adapter type

@auth/drizzle-adapter

Environment

  System:
    OS: macOS 14.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 3.57 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    bun: 1.1.4 - /opt/homebrew/bin/bun
  Browsers:
    Brave Browser: 124.1.65.130
    Chrome: 124.0.6367.119
    Safari: 17.3.1
  npmPackages:
    @auth/drizzle-adapter: ^1.0.1 => 1.0.1 
    @auth/sveltekit: ^1.0.1 => 1.0.1 ```


### Reproduction URL

https://github.com/SlavenIvanov/authjs-drizzle-issue

### Describe the issue

The DrizzleKit adapter doesn't respect the `$defaultFn()`/`$default()` set to the `user.id`  specified in the schema, during user creation.
```ts
import { nanoid } from 'nanoid'

export const users = pgTable('user', {
  id: text('id')
    .primaryKey()
    .$defaultFn(() => nanoid()), // 👈 this here
  name: text('name'),
  email: text('email').notNull(),
  emailVerified: timestamp('emailVerified', { mode: 'date' }),
  image: text('image'),
})

How to reproduce

  1. Clone repo
  2. CD into repo
  3. npm i
  4. docker-compose up -d
  5. Add your OAuth GH credentails in .env
  6. npm run drizzle:push
  7. npm run dev 👉 pageApp
  8. npm run drizzle:studio and open drizzle studio 👉 pageDrizzle
  9. now in pageApp click on Sign In
  10. Open pageDrizzle and navigate to the user table
Screenshot 2024-05-09 at 11 55 00

The Id should be a nanoid() but is a uuid
And we know that the drizzle schema is correct because if you create a new user manually:

Screenshot 2024-05-09 at 11 56 02

The id is correctly picking up the nanoid()

Screenshot 2024-05-09 at 11 56 37

Expected behavior

DrizzleKit Adapter should call the $default()/$defaultFn() instead of generating a uuid for the user.id

@SlavenIvanov SlavenIvanov 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 May 9, 2024
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

1 participant