-
Notifications
You must be signed in to change notification settings - Fork 4k
feat: add default user id generation #9380
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Ignored Deployments
|
* fix: add default user id generation * refactor: simplify `createUser` in adapters * fix typeorm * fix next-auth * fix tests * revert adapter changes * revert * revert * simplify adapter util * fix build errors
|
Hi, Seriously confused why you have changed id to optional on the user object. How are you meant to uniquely identify users now? Some of the logic in your initial post content doesn't make any sense:
This would imply that the user always has an id, because the core library generates one if it's missing. Thanks |
|
Yep, that's the case. Users will always have an id, the whole point of this PR. Feel free to open a bug report if you are experiencing a bug! 🙏 |
|
Hi, Would you be able to explain why the user id field is nullable here then? https://github.com/nextauthjs/next-auth/pull/9380/files#diff-4c2458380e50c967c70d7afe819dc7412180f9f817043f27441de3498e4d0479R469 Thanks |
|
The The one used in database adapters is next-auth/packages/core/src/adapters.ts Line 179 in 665f2bd
|
|
next-auth/packages/core/src/lib/init.ts Lines 45 to 49 in 3f94081
So this is the correct type You can follow #9702 where we might change this and always return Please open issues for bug reports or other concerns, this is a closed PR and not going to be be monitored for further activity. #9380 (comment) this is already fixed just not released yet. It's just a type bug, the object is there as before. |
|
After upgrading to 1.0.12 this change breaks |


Ref: https://twitter.com/Jarpiino/status/1734764485829923040
If the
profile()callback of a provider (that is used to create a new user) does not return anidor it's missing before reaching a database Adapter, we should generate one viacrypto.randomUUID()in the core library. We already did this at the Adapter level, but it's better to do it in the core so it's consistently there.Do the same for the credentials provider's
authorize()method too, markingidoptional when it's not really needed.This should also fix a rather annoying issue that Adapters need to generate an ID in
createUser. Instead we will always pass one for certain, and the adapter can choose to either ignore or use it.NOTE: Using the modified adapters might break next-auth v4, since it would always assume there is an ID coming from#9381next-auth. We can make the same change for the v4 package, but it's likely a breaking change for the adapters. 🤔 I'll likely have to move the adapter changes to a different PR, where we can add a BREAKING CHANGE note to bump these adapters with a major. Will think about it.