@@ -311,13 +311,12 @@ RestWrite.prototype.handleAuthData = function(authData) {
311
311
// need to set the objectId first otherwise location has trailing undefined
312
312
this . data . objectId = userResult . objectId ;
313
313
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
+ }
321
320
// If we didn't change the auth data, just keep going
322
321
if ( ! hasMutatedAuthData ) {
323
322
return ;
@@ -327,13 +326,20 @@ RestWrite.prototype.handleAuthData = function(authData) {
327
326
// We should update the token and let the user in
328
327
// We should only check the mutated keys
329
328
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
+ }
337
343
} ) ;
338
344
} else if ( userId ) {
339
345
// Trying to update auth data but users
0 commit comments