-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set a callback when a user cancels a login request #288
Comments
I'd also like to have this behavior available. |
I have found a workaround for this.... In my scenario, it is kind of equivalent. Hope that helps. |
How do you do this then? I really need this feature as well. A loading spinner is needed in my application but the app does not receive a callback on iOS when the user cancels the permission request. I hope someone can help me with this. Thanks! |
👍 this is really important! |
In the cordova facebook javascript there is this replacement for the fb login method: login: function(params, cb, fail) {
params = params || { scope: '' };
cordova.exec(function(e) { // login
if (e.authResponse && e.authResponse.expiresIn) {
var expirationTime = e.authResponse.expiresIn === 0
? 0
: (new Date()).getTime() + e.authResponse.expiresIn * 1000;
e.authResponse.expirationTime = expirationTime;
}
localStorage.setItem('cdv_fb_session', JSON.stringify(e.authResponse));
FB.Auth.setAuthResponse(e.authResponse, 'connected');
if (cb) cb(e);
}, (fail?fail:null), 'org.apache.cordova.facebook.Connect', 'login', params.scope.split(',') ); You can see that it simply calls the failure callback, and doesn't do anything to actually call the cb method (your call back function). However, if you replace the fail method, it seems like it still doesn't fire (at least on iOS). So from what i can tell this is either a failure on the part of cordova.exec, or somehow the Connect plugin itself is barfing on us. However, there is a "hackish" workaround that I've just figured out. The WorkaroundIn your client FB code, you can do this: var loggedIn = false;
FB.login(function(e) {
if (e.authResponse) {
setTimeout(function() {
loggedIn = true;
}, 0);
alert('user logged in');
else {
// failure, but no handler unforunately
}
setTimeout(function() {
if (!loggedIn) {
alert("Not logged in");
}
}, 1000); If you don't use the setTimeouts, the not logged in code will execute before your logged in code when the user does approve the app. The second setTimeout may not need to be a whole second but it works for me. |
The below code is the solution I used in my application. Hopefully, you'll find that helpful: FB.init({
appId: Surfspace.app.APP_ID,
nativeInterface: CDV.FB,
useCachedDialogs: false
});
FB.getLoginStatus(handleStatusChange);
FB.Event.subscribe('auth.statusChange', handleStatusChange);
// This is the callback function for your login button
function onLoginButtonPress(){
var FB = window.FB;
FB.login(function(result){}, {scope: "email,user_about_me"} );
}
//This is the function that handles the more-verbose 'result' object
function handleStatusChange(session){
if (session.authResponse) {
showLoginLoader(); //here you show tour loading spinner
FB.api('/me', {fields: 'name, id, username, email, gender'}, function(result) {
console.log("FB.api('/me'):" + JSON.stringify(result));
// Check for cancellation/error
if(result.cancelled || result.error) {
console.log("FacebookConnect.login:failedWithError:" + result.message);
removeLoginLoader(); //remove the
return false;
}
// Success - do your thing here.
removeLoginLoader();
});
}
} |
Closing. Out-of-date. |
Expose the "quote" property on share dialogs
Hi,
The FB.login() in Facebook's Javascript SDK also detects when a user cancels a login request. My login callback is only being called when a user confirm the permissions, never when he/she cancels the login request.
Here is and example from Facebook's documentation:
I am asking this because I am adding a loading spinner to the login button, and the spinner should be removed when either, a successful login occurs or a user cancels the login request.
Can this behavior also be achieved with this plugin?
Roei
The text was updated successfully, but these errors were encountered: