Skip to content

Commit 461ddcb

Browse files
committed
Makes sure the location in results has the proper objectId
1 parent d6af77b commit 461ddcb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

spec/ParseUser.spec.js

+26
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,32 @@ describe('Parse.User testing', () => {
14381438
});
14391439
});
14401440

1441+
it('should fail linking with existing', (done) => {
1442+
var provider = getMockFacebookProvider();
1443+
Parse.User._registerAuthenticationProvider(provider);
1444+
Parse.User._logInWith("facebook", {
1445+
success: function(model) {
1446+
let userId = model.id;
1447+
Parse.User.logOut().then(() => {
1448+
request.post({
1449+
url:Parse.serverURL+'/classes/_User',
1450+
headers: {
1451+
'X-Parse-Application-Id': Parse.applicationId,
1452+
'X-Parse-REST-API-Key': 'rest'
1453+
},
1454+
json: {authData: {facebook: provider.authData}}
1455+
}, (err,res, body) => {
1456+
// make sure the location header is properly set
1457+
expect(userId).not.toBeUndefined();
1458+
expect(body.objectId).toEqual(userId);
1459+
expect(res.headers.location).toEqual(Parse.serverURL+'/users/'+userId);
1460+
done();
1461+
});
1462+
});
1463+
}
1464+
});
1465+
});
1466+
14411467
it('should have authData in beforeSave and afterSave', (done) => {
14421468

14431469
Parse.Cloud.beforeSave('_User', (request, response) => {

src/RestWrite.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,12 @@ RestWrite.prototype.handleAuthData = function(authData) {
285285
// Login with auth data
286286
// Short circuit
287287
delete results[0].password;
288+
// need to set the objectId first otherwise location has trailing undefined
289+
this.data.objectId = results[0].objectId;
288290
this.response = {
289291
response: results[0],
290292
location: this.location()
291293
};
292-
this.data.objectId = results[0].objectId;
293294
} else if (this.query && this.query.objectId) {
294295
// Trying to update auth data but users
295296
// are different

0 commit comments

Comments
 (0)