diff --git a/spec/ParseUser.spec.js b/spec/ParseUser.spec.js index 35467752ce..a447b44351 100644 --- a/spec/ParseUser.spec.js +++ b/spec/ParseUser.spec.js @@ -1438,6 +1438,32 @@ describe('Parse.User testing', () => { }); }); + it('should fail linking with existing', (done) => { + var provider = getMockFacebookProvider(); + Parse.User._registerAuthenticationProvider(provider); + Parse.User._logInWith("facebook", { + success: function(model) { + let userId = model.id; + Parse.User.logOut().then(() => { + request.post({ + url:Parse.serverURL+'/classes/_User', + headers: { + 'X-Parse-Application-Id': Parse.applicationId, + 'X-Parse-REST-API-Key': 'rest' + }, + json: {authData: {facebook: provider.authData}} + }, (err,res, body) => { + // make sure the location header is properly set + expect(userId).not.toBeUndefined(); + expect(body.objectId).toEqual(userId); + expect(res.headers.location).toEqual(Parse.serverURL+'/users/'+userId); + done(); + }); + }); + } + }); + }); + it('should have authData in beforeSave and afterSave', (done) => { Parse.Cloud.beforeSave('_User', (request, response) => { diff --git a/src/RestWrite.js b/src/RestWrite.js index e241a98854..cfc79b9291 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -285,11 +285,12 @@ RestWrite.prototype.handleAuthData = function(authData) { // Login with auth data // Short circuit delete results[0].password; + // need to set the objectId first otherwise location has trailing undefined + this.data.objectId = results[0].objectId; this.response = { response: results[0], location: this.location() }; - this.data.objectId = results[0].objectId; } else if (this.query && this.query.objectId) { // Trying to update auth data but users // are different