@@ -288,30 +288,32 @@ RestWrite.prototype.handleAuthData = function(authData) {
288
288
this . storage [ 'authProvider' ] = Object . keys ( authData ) . join ( ',' ) ;
289
289
290
290
if ( results . length > 0 ) {
291
+ const userResult = results [ 0 ] ;
292
+ const mutatedAuthData = { } ;
293
+ Object . keys ( authData ) . forEach ( ( provider ) => {
294
+ const providerData = authData [ provider ] ;
295
+ const userAuthData = userResult . authData [ provider ] ;
296
+ if ( ! _ . isEqual ( providerData , userAuthData ) ) {
297
+ mutatedAuthData [ provider ] = providerData ;
298
+ }
299
+ } ) ;
300
+ const hasMutatedAuthData = Object . keys ( mutatedAuthData ) . length !== 0 ;
291
301
if ( ! this . query ) {
292
302
// Login with auth data
293
303
delete results [ 0 ] . password ;
294
- const userResult = results [ 0 ] ;
295
304
296
305
// need to set the objectId first otherwise location has trailing undefined
297
306
this . data . objectId = userResult . objectId ;
298
307
299
308
// Determine if authData was updated
300
- const mutatedAuthData = { } ;
301
- Object . keys ( authData ) . forEach ( ( provider ) => {
302
- const providerData = authData [ provider ] ;
303
- const userAuthData = userResult . authData [ provider ] ;
304
- if ( ! _ . isEqual ( providerData , userAuthData ) ) {
305
- mutatedAuthData [ provider ] = providerData ;
306
- }
307
- } ) ;
309
+
308
310
this . response = {
309
311
response : userResult ,
310
312
location : this . location ( )
311
313
} ;
312
314
313
315
// If we didn't change the auth data, just keep going
314
- if ( Object . keys ( mutatedAuthData ) . length === 0 ) {
316
+ if ( ! hasMutatedAuthData ) {
315
317
return ;
316
318
}
317
319
// We have authData that is updated on login
@@ -330,10 +332,14 @@ RestWrite.prototype.handleAuthData = function(authData) {
330
332
} else if ( this . query && this . query . objectId ) {
331
333
// Trying to update auth data but users
332
334
// are different
333
- if ( results [ 0 ] . objectId !== this . query . objectId ) {
335
+ if ( userResult . objectId !== this . query . objectId ) {
334
336
throw new Parse . Error ( Parse . Error . ACCOUNT_ALREADY_LINKED ,
335
337
'this auth is already used' ) ;
336
338
}
339
+ // No auth data was mutated, just keep going
340
+ if ( ! hasMutatedAuthData ) {
341
+ return ;
342
+ }
337
343
}
338
344
}
339
345
return this . handleAuthDataValidation ( authData ) ;
0 commit comments