@@ -311,13 +311,12 @@ RestWrite.prototype.handleAuthData = function(authData) {
311311 // need to set the objectId first otherwise location has trailing undefined
312312 this . data . objectId = userResult . objectId ;
313313
314- // Determine if authData was updated
315-
316- this . response = {
317- response : userResult ,
318- location : this . location ( )
319- } ;
320-
314+ if ( ! this . query || ! this . query . objectId ) { // this a login call, no userId passed
315+ this . response = {
316+ response : userResult ,
317+ location : this . location ( )
318+ } ;
319+ }
321320 // If we didn't change the auth data, just keep going
322321 if ( ! hasMutatedAuthData ) {
323322 return ;
@@ -327,13 +326,20 @@ RestWrite.prototype.handleAuthData = function(authData) {
327326 // We should update the token and let the user in
328327 // We should only check the mutated keys
329328 return this . handleAuthDataValidation ( mutatedAuthData ) . then ( ( ) => {
330- // Assign the new authData in the response
331- Object . keys ( mutatedAuthData ) . forEach ( ( provider ) => {
332- this . response . response . authData [ provider ] = mutatedAuthData [ provider ] ;
333- } ) ;
334- // Run the DB update directly, as 'master'
335- // Just update the authData part
336- return this . config . database . update ( this . className , { objectId : this . data . objectId } , { authData : mutatedAuthData } , { } ) ;
329+ // IF we have a response, we'll skip the database operation / beforeSave / afterSave etc...
330+ // we need to set it up there.
331+ // We are supposed to have a response only on LOGIN with authData, so we skip those
332+ // If we're not logging in, but just updating the current user, we can safely skip that part
333+ if ( this . response ) {
334+ // Assign the new authData in the response
335+ Object . keys ( mutatedAuthData ) . forEach ( ( provider ) => {
336+ this . response . response . authData [ provider ] = mutatedAuthData [ provider ] ;
337+ } ) ;
338+ // Run the DB update directly, as 'master'
339+ // Just update the authData part
340+ // Then we're good for the user, early exit of sorts
341+ return this . config . database . update ( this . className , { objectId : this . data . objectId } , { authData : mutatedAuthData } , { } ) ;
342+ }
337343 } ) ;
338344 } else if ( userId ) {
339345 // Trying to update auth data but users
0 commit comments