2 years ago

#14923

test-img

Trevor Dammon

FaceBook JavaScript SDK no response is sent when login cancelled

I am working with the FaceBook JavaScript SDK to log users in via FaceBook SSO. documentation

Clicking the SSO button opens a new window prompting the user to log in via FaceBook. If the user logs in there is no issue. However, if the user exits or cancels the SSO, I am not getting a response from FB.

Here is the function given in the FB documentation:

FB.login(function(response) {
    if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('Good to see you, ' + response.name + '.');
     });
    } else {
     console.log('User cancelled login or did not fully authorize.');
    }
});

I have tried using this function exactly and again if I cancel the SSO the else block never runs as I would expect it to.

I am trying to modify the function slightly but I still am not able to get a response when the page is cancelled.

    static login(callbacks, { mode = "login" }) {
        const FB = window.FB;
        FB.login(
            (res) => {
                console.log(res);
                const { authResponse } = res;
                if (mode === "login") {
                    Facebook.socialSignOn(authResponse, callbacks);
                } else if (mode === "verify") {
                    Facebook.socialVerify(authResponse, callbacks);
                }
            },
            { return_scopes: "true", scope: "email" }
        );
    }

UPDATE

After playing around more it seems like if I try to use the FB SSO, cancel, and then try again all future FB.login() attempts immediately receive a response with authResponse : null

javascript

facebook

facebook-javascript-sdk

0 Answers

Your Answer

Accepted video resources