From 4f643d970a947bc1446d4161ad1b90dfe2d4dd36 Mon Sep 17 00:00:00 2001 From: Long Nguyen Date: Sun, 6 Mar 2016 01:32:50 +0700 Subject: [PATCH] Fix create wrong _Session for Facebook login --- spec/RestCreate.spec.js | 9 +++++++++ src/RestWrite.js | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/RestCreate.spec.js b/spec/RestCreate.spec.js index cddfd598d0..f9b94b379e 100644 --- a/spec/RestCreate.spec.js +++ b/spec/RestCreate.spec.js @@ -175,17 +175,26 @@ describe('rest create', () => { } } }; + var newUserSignedUpByFacebookObjectId; rest.create(config, auth.nobody(config), '_User', data) .then((r) => { expect(typeof r.response.objectId).toEqual('string'); expect(typeof r.response.createdAt).toEqual('string'); expect(typeof r.response.sessionToken).toEqual('string'); + newUserSignedUpByFacebookObjectId = r.response.objectId; return rest.create(config, auth.nobody(config), '_User', data); }).then((r) => { expect(typeof r.response.objectId).toEqual('string'); expect(typeof r.response.createdAt).toEqual('string'); expect(typeof r.response.username).toEqual('string'); expect(typeof r.response.updatedAt).toEqual('string'); + expect(r.response.objectId).toEqual(newUserSignedUpByFacebookObjectId); + return rest.find(config, auth.master(config), + '_Session', {sessionToken: r.response.sessionToken}); + }).then((response) => { + expect(response.results.length).toEqual(1); + var output = response.results[0]; + expect(output.user.objectId).toEqual(newUserSignedUpByFacebookObjectId); done(); }); }); diff --git a/src/RestWrite.js b/src/RestWrite.js index a907a61c32..d42f2f4524 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -178,7 +178,11 @@ RestWrite.prototype.setRequiredFieldsIfNeeded = function() { this.data.updatedAt = this.updatedAt; if (!this.query) { this.data.createdAt = this.updatedAt; - this.data.objectId = cryptoUtils.newObjectId(); + + // Only assign new objectId if we are creating new object + if (!this.data.objectId) { + this.data.objectId = cryptoUtils.newObjectId(); + } } } return Promise.resolve();