Closed nbouvrette closed 1 year ago
It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!
Bump
It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!
Looks like this issue has already been fixed by looking at the current types.
I think this still must allow returning null - what if I provide incorrect id?
Not sure what you mean @MonstraG - this is about the argument's type - it should always pass a valid id, otherwise how can there be a session?
well getUser
returns AdapterUser | null
, and updateUser
calls getUser
, so it have to return null?
I think the Adapter's getUser
can return null
is the user doesn't exist, but I don't think it make sense in the updateUser
context. I actually have this code in my Adapter, which should honestly never be triggered but that does fix the type issue you are describing:
if (!user) {
throw new Error('user was not found while updating a next-auth user')
}
Environment
This applies to the latest version of next-auth.
Reproduction URL
https://github.com/nextauthjs/next-auth/blob/6132c3fa751b647dd8261ac9b30e24fb140a2f1a/packages/next-auth/src/adapters.ts#L87
Describe the issue
When creating an adapter, because
updateUser
expects auser: Partial<AdapterUser>
this means that theuser.id
ca beundefined
.This means if we follow the type definition that this method can be called without a user id, and the expectation is that it returns a valid user object... which makes no sense.
I think that the correct signature should be:
updateUser: (user: Pick<AdapterUser, 'id'> & Partial<Omit<AdapterUser, 'id'>>) => Awaitable<AdapterUser>
How to reproduce
And try to create an adapter that implements the
updateUser
method - you will see that the user id can beundefined
as per the type definition here: https://github.com/nextauthjs/next-auth/blob/6132c3fa751b647dd8261ac9b30e24fb140a2f1a/packages/next-auth/src/adapters.ts#L87Expected behavior
I would expect the user id to always be provided in
updateUser
, or if there is a reason it won't be provided, then the method should also allow returningnull
instead of a user object.I'm not familiar enough with next-auth to know if this could happen, but the current signature does feel odd.