Persist changed profile fields while retaining the existing user identifier.
Profile editing
Auth.js · Enum
updateUser is an optional Auth.js adapter method for persisting changes to an existing user. It receives partial user data with a required id and returns the updated AdapterUser.
updateUser is an optional adapter method. Auth.js passes a partial user object that always includes the user’s id; the adapter applies those changes in its database and returns the complete updated AdapterUser.
optional updateUser(user): Awaitable<AdapterUser>| Name | Type | Description |
|---|---|---|
user | Partial<AdapterUser> & Pick<AdapterUser, "id"> | A partial user update whose id property is required for locating the database record. |
Awaitable<AdapterUser>
updateUser is optional on the adapter interface and may resolve synchronously or asynchronously to an AdapterUser.id is required; use it to select the record rather than assuming every user field is present.import type { Adapter, AdapterUser } from "next-auth/adapters"
export const adapter: Adapter = {
async updateUser(user) {
const updated: AdapterUser = await db.user.update({
where: { id: user.id },
data: user,
})
return updated
},
}Implements the adapter method by updating the persisted user identified by id and returning the resulting adapter user.
Profile editing
Account lifecycle management
updateUser do, and what does it return?updateUser is an optional adapter method that updates a user in the database and returns the updated AdapterUser. Its argument is a partial adapter user combined with a required id.
Follow-up: What must an implementation do if only name is supplied? It should update only the supplied field for the user selected by id, then return the complete persisted user.
updateUser?The method receives Partial<AdapterUser> & Pick<AdapterUser, "id">. Therefore, callers may omit mutable user properties, but the identifier is always available for locating the record.
Follow-up: Why should the implementation avoid replacing the whole row? Because omitted properties are valid in the partial input and should not be overwritten accidentally.
updateUser connected to Auth.js configuration?An adapter is passed to Auth.js through the adapter configuration option. The adapter methods provide persistence operations, including updating users.
Follow-up: How does this relate to the adapter contract? The implementation must conform to the Adapter interface and return an AdapterUser after persistence succeeds.
AdapterAdapterUsercreateUsergetUserdeleteUserUser management