Skip to content

Commit 51db176

Browse files
Stanislawvengrov
authored andcommitted
fix: if user call enablePromises and pass stayLoggedIn flag to social login methods, the async callback will not be called (#27)
* fix: if user called enablePromises and pass stayLoggedIn flag to social login methods, the async callback will be not called * fixed typescript definition according to change social login methods * fix: revert functions signature, extract async cb from arguments * refactor: order of arguments changed * fixed typescript definition according to change
1 parent df7b93d commit 51db176

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

libs/backendless.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ declare module __Backendless {
795795

796796
loginWithFacebook(fields?:Object, permissions?:Object, async?:Backendless.Async, stayLoggedIn?:boolean):void;
797797

798-
loginWithGooglePlus(fields?:Object, permissions?:Object, async?:Backendless.Async, container?:HTMLElement, stayLoggedIn?:boolean):void;
798+
loginWithGooglePlus(fields?:Object, permissions?:Object, container?:HTMLElement, async?:Backendless.Async, stayLoggedIn?:boolean):void;
799799

800800
loginWithTwitter(fields?:Object, async?:Backendless.Async, stayLoggedIn?:boolean):void;
801801

libs/backendless.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,16 +1702,19 @@
17021702
return isAsync ? result : this._parseResponse(result);
17031703
},
17041704

1705-
loginWithFacebook : function(facebookFieldsMapping, permissions, callback, stayLoggedIn) {
1706-
this._loginSocial('Facebook', facebookFieldsMapping, permissions, callback, null, stayLoggedIn);
1705+
loginWithFacebook : function(facebookFieldsMapping, permissions, async, stayLoggedIn) {
1706+
async = extractResponder(arguments);
1707+
this._loginSocial('Facebook', facebookFieldsMapping, permissions, async, null, stayLoggedIn);
17071708
},
17081709

1709-
loginWithGooglePlus : function(googlePlusFieldsMapping, permissions, callback, container, stayLoggedIn) {
1710-
this._loginSocial('GooglePlus', googlePlusFieldsMapping, permissions, callback, container, stayLoggedIn);
1710+
loginWithGooglePlus : function(googlePlusFieldsMapping, permissions, async, container, stayLoggedIn) {
1711+
async = extractResponder(arguments);
1712+
this._loginSocial('GooglePlus', googlePlusFieldsMapping, permissions, async, container, stayLoggedIn);
17111713
},
17121714

1713-
loginWithTwitter : function(twitterFieldsMapping, callback, stayLoggedIn) {
1714-
this._loginSocial('Twitter', twitterFieldsMapping, null, callback, null, stayLoggedIn);
1715+
loginWithTwitter : function(twitterFieldsMapping, async, stayLoggedIn) {
1716+
async = extractResponder(arguments);
1717+
this._loginSocial('Twitter', twitterFieldsMapping, null, async, null, stayLoggedIn);
17151718
},
17161719

17171720
_socialContainer : function(socialType, container) {
@@ -1772,23 +1775,20 @@
17721775
}
17731776
},
17741777

1775-
_loginSocial: function(socialType, fieldsMapping, permissions, callback, container, stayLoggedIn) {
1778+
_loginSocial: function(socialType, fieldsMapping, permissions, async, container, stayLoggedIn) {
17761779
var socialContainer = new this._socialContainer(socialType, container);
1777-
var responder = extractResponder(arguments);
1778-
if (responder) {
1779-
responder = this._wrapAsync(responder);
1780-
}
1780+
async = async && this._wrapAsync(async);
17811781

17821782
Utils.addEvent('message', window, function(e) {
17831783
if (e.origin == Backendless.serverURL) {
17841784
var result = JSON.parse(e.data);
17851785

17861786
if (result.fault) {
1787-
responder.fault(result.fault);
1787+
async.fault(result.fault);
17881788
} else {
17891789
Backendless.LocalCache.set("stayLoggedIn", !!stayLoggedIn);
17901790
currentUser = this.Backendless.UserService._parseResponse(result);
1791-
responder.success(this.Backendless.UserService._getUserFromResponse(currentUser));
1791+
async.success(this.Backendless.UserService._getUserFromResponse(currentUser));
17921792
}
17931793

17941794
Utils.removeEvent('message', window);
@@ -1800,7 +1800,7 @@
18001800
socialContainer.doAuthorizationActivity(r);
18011801
}, function(e) {
18021802
socialContainer.closeContainer();
1803-
responder.fault(e);
1803+
async.fault(e);
18041804
});
18051805

18061806
var request = {};
@@ -4191,7 +4191,7 @@
41914191
lastFlushListeners = null;
41924192
}
41934193
}
4194-
}
4194+
};
41954195

41964196
if (async) {
41974197
listeners = lastFlushListeners = lastFlushListeners ? lastFlushListeners.splice(0) : [];
@@ -4348,7 +4348,7 @@
43484348
'getCategories', 'deleteCategory', 'deletePoint']],
43494349
[UserService.prototype, ['register', 'getUserRoles', 'roleHelper', 'login', 'describeUserClass',
43504350
'restorePassword', 'logout', 'update', 'isValidLogin', 'loginWithFacebookSdk',
4351-
'loginWithGooglePlusSdk','loginWithFacebook', 'loginWithGooglePlus', 'loginWithTwitter']]
4351+
'loginWithGooglePlusSdk', 'loginWithGooglePlus', 'loginWithTwitter', 'loginWithFacebook']]
43524352
].forEach(promisifyPack);
43534353

43544354
UserService.prototype.getCurrentUser = function() {

tests/tsd.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -353,31 +353,39 @@ function testUserService() {
353353
Backendless.UserService.loginWithFacebook({});
354354
Backendless.UserService.loginWithFacebook({}, {});
355355
Backendless.UserService.loginWithFacebook({}, {}, async);
356-
Backendless.UserService.loginWithFacebook({}, null, async);
357-
Backendless.UserService.loginWithFacebook(null, null, async);
358-
Backendless.UserService.loginWithFacebook({}, {}, async, document.createElement('div'));
359-
Backendless.UserService.loginWithFacebook({}, {}, null, document.createElement('div'));
356+
Backendless.UserService.loginWithFacebook({}, {}, async, true);
357+
Backendless.UserService.loginWithFacebook({}, {}, null, true);
358+
Backendless.UserService.loginWithFacebook({}, null, null, true);
359+
Backendless.UserService.loginWithFacebook(null, null, null, true);
360360

361361
Backendless.UserService.loginWithGooglePlus();
362362
Backendless.UserService.loginWithGooglePlus({});
363363
Backendless.UserService.loginWithGooglePlus({}, {});
364-
Backendless.UserService.loginWithGooglePlus({}, {}, async);
365-
Backendless.UserService.loginWithGooglePlus({}, null, async);
366-
Backendless.UserService.loginWithGooglePlus(null, null, async);
367-
Backendless.UserService.loginWithGooglePlus({}, {}, async, document.createElement('div'));
368-
Backendless.UserService.loginWithGooglePlus({}, {}, null, document.createElement('div'));
364+
Backendless.UserService.loginWithGooglePlus({}, {}, document.createElement('div'));
365+
Backendless.UserService.loginWithGooglePlus({}, {}, document.createElement('div'), async);
366+
Backendless.UserService.loginWithGooglePlus({}, {}, document.createElement('div'), async, true);
367+
Backendless.UserService.loginWithGooglePlus({}, {}, document.createElement('div'), null, true);
368+
Backendless.UserService.loginWithGooglePlus({}, {}, null, null, true);
369+
Backendless.UserService.loginWithGooglePlus({}, null, null, null, true);
370+
Backendless.UserService.loginWithGooglePlus(null, null, null, null, true);
369371

370372
Backendless.UserService.loginWithTwitter();
371373
Backendless.UserService.loginWithTwitter({}, async);
372-
Backendless.UserService.loginWithTwitter(null, async);
374+
Backendless.UserService.loginWithTwitter({}, async, true);
375+
Backendless.UserService.loginWithTwitter({}, null, true);
376+
Backendless.UserService.loginWithTwitter(null, null, true);
373377

374378
Backendless.UserService.loginWithFacebookSdk();
375-
Backendless.UserService.loginWithFacebookSdk({}, async);
376-
Backendless.UserService.loginWithFacebookSdk(null, async);
379+
Backendless.UserService.loginWithFacebookSdk({}, true);
380+
Backendless.UserService.loginWithFacebookSdk({}, true, async);
381+
Backendless.UserService.loginWithFacebookSdk({}, null, async);
382+
Backendless.UserService.loginWithFacebookSdk(null, null, async);
377383

378384
Backendless.UserService.loginWithGooglePlusSdk();
379-
Backendless.UserService.loginWithGooglePlusSdk({}, async);
380-
Backendless.UserService.loginWithGooglePlusSdk(null, async);
385+
Backendless.UserService.loginWithGooglePlusSdk({}, true);
386+
Backendless.UserService.loginWithGooglePlusSdk({}, true, async);
387+
Backendless.UserService.loginWithGooglePlusSdk({}, null, async);
388+
Backendless.UserService.loginWithGooglePlusSdk(null, null, async);
381389

382390
bol = Backendless.UserService.isValidLogin();
383391
resultXHR = Backendless.UserService.isValidLogin(async);

0 commit comments

Comments
 (0)