-
-
Notifications
You must be signed in to change notification settings - Fork 88
fix: allow user ID to be passed as a string #46
Conversation
Casting each |
@kripod I'm not sure how casting to a string would be compatible with the Prisma adapter and schema. The point of this PR is to enable strings and numbers to be passed as the Here is the Maybe you can clarify your comment? Personally, I would like to use ccid or uuid, which would be strings, as the user ID but #38 shows that isn't possible today. |
There are no runtime changes to be made. The current code already handles both string and number IDs correctly – only the types aren’t correct. |
I think I understand but I would like to make sure we're on the same page... Without these code changes, I encounter a silent error. Specifically, when next-auth gets Are you saying we should change, for example, If what I just wrote matches your feedback then I will update the PR accordingly. Thanks! |
Thanks for your feedback! I wasn’t aware of the JWT case as I’ve been using a stored session approach all along. In my case, transforming only the types has worked flawlessly. As strings cannot be casted into IEEE 754 numbers without data loss, I would advise against changes like below: const _userId = Number(userId); Casting the other way (from numbers to strings) could work, though, but I’m not sure what the benefit of that would be: const _userId = String(userId); |
@kripod Based on this comment do you still want me to update this PR for merging? If so, I will be happy to make the changes requested above. |
@sir-dunxalot Since this PR was opened, #72 has landed, which suggests the use of string IDs instead of numbers. I think this is resolved now. |
Fixes/supersedes nextauthjs/next-auth#1644
Per the JWT spec (sub section), a token's
sub
is a string. Thus, if next-auth is callinggetUser(sub)
(example here), you're passing a string to getUser(). This PR addresses this incompatibility by allowinguserId
to be passed into the Prisma adapter's methods as either a string or a number.