Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 297
Hrashikesh Naik Avatar asked Apr 21 '21 12:04

Hrashikesh Naik


1 Answers

It seems like FB.logout now has reqired param: cb.

https://developers.facebook.com/docs/reference/javascript/FB.logout/

Not sure when it became mandatory, but it is not working without it anymore.

like image 190
SerjDDD Avatar answered Nov 18 '22 02:11

SerjDDD