nextauthjs / next-auth

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

ID not beeing created in the database #11124

Open ZzyzxIsAlreadyTaken opened 1 month ago

ZzyzxIsAlreadyTaken commented 1 month ago

Adapter type

@auth/drizzle-adapter

Environment

System: OS: macOS 14.5 CPU: (12) arm64 Apple M2 Max Memory: 53.95 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm Browsers: Chrome: 125.0.6422.142 Safari: 17.5 npmPackages: @auth/drizzle-adapter: ^1.1.0 => 1.2.0 next: ^14.2.1 => 14.2.3 next-auth: ^4.24.7 => 4.24.7 react: ^18.3.0 => 18.3.1

Reproduction URL

https://github.com/ZzyzxIsAlreadyTaken/monthly

Describe the issue

The issue is that the ID in the users table is not created when logging in. The session is kind of started, but the user is never created in the local db for some reason. 
When I change the ID to Integer and autoincremenet the authentication works. But I know this will break other stuff.

Now auth.ts complains that the userstable has int but should have text.

![Screenshot 2024-06-10 at 11 53 25](https://github.com/nextauthjs/next-auth/assets/18461079/7adb08be-ccf7-4cf7-a4e4-494d21933ddd)

[next-auth][debug][adapter_getUserByEmail] { args: [ 'somemail@hotmail.com' ] } [next-auth][debug][adapter_createUser] { args: [ { name: 'someusername', email: 'somemail@hotmail.com', image: 'https://cdn.discordapp.com/embed/avatars/0.png', emailVerified: null } ] } [next-auth][error][adapter_error_createUser] https://next-auth.js.org/errors#adapter_error_createuser NOT NULL constraint failed: monthly_user.id { message: 'NOT NULL constraint failed: monthly_user.id',

Also getting this: Screenshot 2024-06-09 at 23 32 09@2x

Turned on debugging in nexauth options and is getting the same error both with discord and google providers. Both are getting the users, but creating database entry fails with no userid beeing updated.

How to reproduce

Create T3 app with sqlite and drizzle, set up basic client id, secret and callback for Discord and Google.

Expected behavior

User beeing created in db, and login succeded

Infiplaya commented 1 month ago

I have the same problem, have u fixed it?

mbilenko-florio commented 1 month ago

If you generated template with t3, try modifying your sqlite schema like this https://github.com/ZzyzxIsAlreadyTaken/monthly/commit/385c95aecd8993a9616c017711dba425adea7c34

ZzyzxIsAlreadyTaken commented 1 month ago

Yeah mbilenko-florio has the fix. I reported it in T3 aswell. The error is the same with some other adapters, and with similar solutions. My github and databse schema should be updated with the solution.