Merge fields instead of overwriting whole doc #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've discovered that the updateUser method of the adapter in Firestore overwrites the record if it already exists. This results in user information being lost upon update. For example, when logging in with the email provider.
Right now the bug is this:
next-auth
calls theupdateUser
method of the adapter with the data:This pull request sets the
merge
flag on the firebaseset
command totrue
so that the record isn't overwritten.However, this isn't enough, because
next-auth
expects to receive the updated record including the original fields, which means we need to somehow get the original fields (otherwise, the session won't include the user's profile).Unfortunately, the firebase javascript SDK (unlike the REST API) does not return the updated record in response to
set
orcreate
calls (see here). As a consequence, we must make an additional call to retrieve the updated record, and then return that tonext-auth
.This pull request takes care of both of these changes. Please keep in mind that I have not updated any other methods or anything outside of the firestore database (if the firebase file needs to be updated as well, this should be done, too. However, I am unfamiliar with it).