thebergamo / react-native-fbsdk-next

MIT License
633 stars 165 forks source link

LoginManager.logOut() doesn't remove app from Facebook "Business Integrations" #519

Closed sufian1999 closed 2 weeks ago

sufian1999 commented 2 weeks ago

This is my FB logout function. This function does not give any error but after executing this function when I go to Business Integrations in my FB account, my app is still there. I want to remove it from there as well.

import { AccessToken, GraphRequest, GraphRequestManager, LoginManager, } from 'react-native-fbsdk-next';

const FbLogout = async (loaderValue: boolean) => {

    setloading(loaderValue == false ? false : true)
    setloading2(loaderValue == false ? true : false)

    LoginManager.logOut()

    const user: any = await AsyncStorage.getItem("user")
    const newuser = JSON.parse(user)      

    await axios.get(`${api.disconnectIntegration}AgentID=${newuser?.id}`)
    .then(res => {

        console.log('response=================>', res.data)

        setloading(false)
        setloading2(false)

        props.navigation.navigate(routes.MainIntegration)

    })
    .catch(err => {
        console.log(err)

        setloading(false)
        setloading2(false)

    })

}

I'm using these permissions:
export const FBPermissionsArray = [
'public_profile',
'pages_show_list',
'pages_manage_ads',
'pages_read_engagement',
'leads_retrieval',
'ads_management',
'pages_manage_metadata',
'business_management'
// 'pages_manage_posts', 

]

sufian1999 commented 2 weeks ago

I fixed my problem by removing permissions at the time of logout.

`const FbLogout = async (loaderValue: boolean) => {

    setloading(loaderValue == false ? false : true)
    setloading2(loaderValue == false ? true : false)

    // LoginManager.logOut()
    AccessToken.getCurrentAccessToken().then(async data => {
        console.log('device token data>>>>>',data);

        const accessToken: any = data?.accessToken.toString();
        await RemovePermissionsAndLogout(accessToken)
    })

}`

`const RemovePermissionsAndLogout = (accessToken: string) => {
    let logout =
        new GraphRequest(
            "me/permissions/",
            {
                accessToken: accessToken,
                httpMethod: 'DELETE'
            },
            async (error, result) => {
                if (error) 
                {
                    console.error('You didn\'t integrate from this device. Please disconnect your integration from the previous device: ' + error);
                    LogoutAndRemoveInt()
                } 
                else 
                {
                    LogoutAndRemoveInt()
                }
            });
    new GraphRequestManager().addRequest(logout).start();
};`

`const LogoutAndRemoveInt = async () => {

    LoginManager.logOut();

    const user: any = await AsyncStorage.getItem("user")
    const newuser = JSON.parse(user)      

    await axios.get(`${api.disconnectIntegration}AgentID=${newuser?.id}`)
    .then(res => {

        console.log('response=================>', res.data)

        setloading(false)
        setloading2(false)

        props.navigation.navigate(routes.MainIntegration)

    })
    .catch(err => {
        console.log(err)

        setloading(false)
        setloading2(false)

    })

}`