Skip to content

Commit 1a723c6

Browse files
committed
Merge pull request #857 from tobernguyen/master
Fix create wrong _Session for Facebook login
2 parents 930e842 + fcc8032 commit 1a723c6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spec/RestCreate.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,26 @@ describe('rest create', () => {
175175
}
176176
}
177177
};
178+
var newUserSignedUpByFacebookObjectId;
178179
rest.create(config, auth.nobody(config), '_User', data)
179180
.then((r) => {
180181
expect(typeof r.response.objectId).toEqual('string');
181182
expect(typeof r.response.createdAt).toEqual('string');
182183
expect(typeof r.response.sessionToken).toEqual('string');
184+
newUserSignedUpByFacebookObjectId = r.response.objectId;
183185
return rest.create(config, auth.nobody(config), '_User', data);
184186
}).then((r) => {
185187
expect(typeof r.response.objectId).toEqual('string');
186188
expect(typeof r.response.createdAt).toEqual('string');
187189
expect(typeof r.response.username).toEqual('string');
188190
expect(typeof r.response.updatedAt).toEqual('string');
191+
expect(r.response.objectId).toEqual(newUserSignedUpByFacebookObjectId);
192+
return rest.find(config, auth.master(config),
193+
'_Session', {sessionToken: r.response.sessionToken});
194+
}).then((response) => {
195+
expect(response.results.length).toEqual(1);
196+
var output = response.results[0];
197+
expect(output.user.objectId).toEqual(newUserSignedUpByFacebookObjectId);
189198
done();
190199
});
191200
});

src/RestWrite.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ RestWrite.prototype.setRequiredFieldsIfNeeded = function() {
178178
this.data.updatedAt = this.updatedAt;
179179
if (!this.query) {
180180
this.data.createdAt = this.updatedAt;
181-
this.data.objectId = cryptoUtils.newObjectId();
181+
182+
// Only assign new objectId if we are creating new object
183+
if (!this.data.objectId) {
184+
this.data.objectId = cryptoUtils.newObjectId();
185+
}
182186
}
183187
}
184188
return Promise.resolve();

0 commit comments

Comments
 (0)