Fix/user update issue (#4123)

* Adds failing test,

the _User object is not updated as soon as you pass some authData part of the PUT

* Do not run the DB call when updating the user with new auth data, just part of the rest
This commit is contained in:
Florent Vilmart
2017-08-29 16:34:59 -04:00
committed by GitHub
parent a103871cbc
commit 2e1ba66fd2
2 changed files with 74 additions and 14 deletions

View File

@@ -311,13 +311,12 @@ RestWrite.prototype.handleAuthData = function(authData) {
// need to set the objectId first otherwise location has trailing undefined
this.data.objectId = userResult.objectId;
// Determine if authData was updated
this.response = {
response: userResult,
location: this.location()
};
if (!this.query || !this.query.objectId) { // this a login call, no userId passed
this.response = {
response: userResult,
location: this.location()
};
}
// If we didn't change the auth data, just keep going
if (!hasMutatedAuthData) {
return;
@@ -327,13 +326,20 @@ RestWrite.prototype.handleAuthData = function(authData) {
// We should update the token and let the user in
// We should only check the mutated keys
return this.handleAuthDataValidation(mutatedAuthData).then(() => {
// Assign the new authData in the response
Object.keys(mutatedAuthData).forEach((provider) => {
this.response.response.authData[provider] = mutatedAuthData[provider];
});
// Run the DB update directly, as 'master'
// Just update the authData part
return this.config.database.update(this.className, {objectId: this.data.objectId}, {authData: mutatedAuthData}, {});
// IF we have a response, we'll skip the database operation / beforeSave / afterSave etc...
// we need to set it up there.
// We are supposed to have a response only on LOGIN with authData, so we skip those
// If we're not logging in, but just updating the current user, we can safely skip that part
if (this.response) {
// Assign the new authData in the response
Object.keys(mutatedAuthData).forEach((provider) => {
this.response.response.authData[provider] = mutatedAuthData[provider];
});
// Run the DB update directly, as 'master'
// Just update the authData part
// Then we're good for the user, early exit of sorts
return this.config.database.update(this.className, {objectId: this.data.objectId}, {authData: mutatedAuthData}, {});
}
});
} else if (userId) {
// Trying to update auth data but users