FB.logout in JS project gives error "Expression is of type undefined, not function"

Viewed 544

I'm trying to add Login with FB on my react website.

FB.init({
    appId      : app_id,
    cookie     : true,
    xfbml      : true,
    version    : 'v5.0'
});

Followed by

FB.getLoginStatus(({status}) => {
    if (status === 'connected') {
        FB.logout();
    }
    FB.login((response) => {
        if (response.authResponse) {
            const {authResponse: {accessToken}} = response;
            onSuccess(accessToken);
        } else {
            onError({error: 'popup_closed_by_user'});
        }
    }, {scope: 'email'});
})

But it's opening the popup the first time (when getLoginStatus is not connected) and then the 2nd time it shows an error on the console

Uncaught b { innerError: undefined, message: "Expression is of type undefined, not function" }

Upon further investigation, I found that the error happens when the line FB.logout() is called.

What might I be doing wrong?

NOTE The same code was working until yesterday.

1 Answers
Related