Skip to content

Commit bfe1c24

Browse files
committed
more elegant
1 parent 55528a6 commit bfe1c24

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

spec/ParseUser.spec.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,17 +1178,19 @@ describe('Parse.User testing', () => {
11781178
return user._linkWith('facebook', {});
11791179
}).then(user => {
11801180
expect(user._isLinked("facebook")).toBeTruthy();
1181-
return Parse.User._logInWith('facebook', {});
1181+
// We should logout here as session token is passed
1182+
// Probably need a fix in the JS SDK to handle those
1183+
// linking errors
1184+
return Parse.User.logOut().then(() => {
1185+
return Parse.User._logInWith('facebook', {});
1186+
});
11821187
}).then(user => {
11831188
const fileAgain = user.get('file');
11841189
expect(fileAgain.name()).toMatch(/yolo.txt$/);
11851190
expect(fileAgain.url()).toMatch(/yolo.txt$/);
11861191
}).then(() => {
11871192
done();
1188-
}, error => {
1189-
jfail(error);
1190-
done();
1191-
});
1193+
}).catch(done.fail);
11921194
});
11931195

11941196
it("log in with provider twice", (done) => {

src/RestWrite.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,7 @@ RestWrite.prototype.handleAuthData = function(authData) {
297297
}
298298
});
299299
const hasMutatedAuthData = Object.keys(mutatedAuthData).length !== 0;
300-
let userId;
301-
if (this.query && this.query.objectId) {
302-
userId = this.query.objectId;
303-
} else if (this.auth && this.auth.user && this.auth.user.id) {
304-
userId = this.auth.user.id;
305-
}
306-
if (!userId) { // no user making the call
300+
if (!this.query) {
307301
// Login with auth data
308302
delete results[0].password;
309303

@@ -334,10 +328,10 @@ RestWrite.prototype.handleAuthData = function(authData) {
334328
// Just update the authData part
335329
return this.config.database.update(this.className, {objectId: this.data.objectId}, {authData: mutatedAuthData}, {});
336330
});
337-
} else if (userId) {
331+
} else if (this.query && this.query.objectId) {
338332
// Trying to update auth data but users
339333
// are different
340-
if (userResult.objectId !== userId) {
334+
if (userResult.objectId !== this.query.objectId) {
341335
throw new Parse.Error(Parse.Error.ACCOUNT_ALREADY_LINKED,
342336
'this auth is already used');
343337
}

src/Routers/UsersRouter.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ export class UsersRouter extends ClassesRouter {
2626
const data = deepcopy(req.body);
2727
req.body = data;
2828
req.params.className = '_User';
29+
if (req.auth.user) {
30+
// this is authenticated
31+
// treat it as an update
32+
req.params.objectId = req.auth.user.id;
33+
return super.handleUpdate(req);
34+
}
2935

3036
return super.handleCreate(req);
3137
}

0 commit comments

Comments
 (0)