How to logout from facebook with LoginManager provided by react-native-fbsdk?

12,179

Solution 1

I think its not a synchronous function but also I think you don't need to wait for it to finish. You can just use it as synchronous. I'm thinking this because if you check the default LoginButton on react-native-fbsdk onLogoutFinished prop doesn't pass any parameters about the logout action (successful, failed etc.). This means you can assume that its gonna happen without any problem since facebook itself assumed that. Default LoginButton listens for events to run onLogoutFinished function. You can try to implement something like that if you really need to.

Solution 2

For me, this works:

import { LoginManager } from 'react-native-fbsdk'
LoginManager.logOut()
Share:
12,179
Ville Miekk-oja
Author by

Ville Miekk-oja

Updated on July 02, 2022

Comments

  • Ville Miekk-oja
    Ville Miekk-oja almost 2 years

    In simple, how does one log out with LoginManager provided by react-native-fbsdk?

    If we look the code inside that LoginManager provided by react-native-fbsdk, we find this part regarding logout:

      logOut() {
        LoginManager.logOut();
      },
    

    So no callback, or promise? How do I really use this then? If I call LoginManager.logout(), it actually does perform the logout. But since I'm not allowed to pass any callback, and since it doesn't return a promise, then how do I know when the logout is done, or that was it successfull? I tried providing a callback, but it resulted in error. I also tried to return a promise from it, but it also returned an error. So I don't know how is this supposed to be used? It can't be synchronous logout, right?

  • Fatih Ayyildiz
    Fatih Ayyildiz over 6 years
    hi @bennygenel, Can i ask to you further info about this answer ? I want to trigger logout step from different page. I called LoginManager.logOut() but do nothing. How can i call logout function for react-native-fbsdk ?
  • bennygenel
    bennygenel over 6 years
    @FatihAyyildiz if you didn't get any errors probably the function worked and you logged out from facebook but you need to handle logging out from your app too. Its hard to tell more without seeing a minimal reproducible example. If you can't figure it out you can always create a new question with your specific case.
  • Fatih Ayyildiz
    Fatih Ayyildiz about 6 years
    I made my repo to public. Could you check this repo to understand problem with facebook logout https://github.com/fatihayyildiz/raffleapp
  • bennygenel
    bennygenel about 6 years
    @FatihAyyildiz I checked your code and can't find anything really. Maybe you should create a new question with a minimal reproducible example. Someone else might help better than me.
  • Çağdaş Tunca
    Çağdaş Tunca about 6 years
    import { LoginManager } from 'react-native-fbsdk'; ... LoginManager.logOut(); works perfectly on me.
  • Haseeb Burki
    Haseeb Burki over 4 years
    @ÇağdaşTunca after logging out can you sign up with another user? When I log out using loginManager.logOut() it does not let me enter the username and password for a different account. It keeps logging in with the same account
  • Çağdaş Tunca
    Çağdaş Tunca over 4 years
    @HaseebBurki When you login with fbsdk app or web app opens and user enter his/hers crentials after you logout user with this way user logs out facebook within your app. Roughly speaking You can not call facebook apis with this user in your app anymore but user is still logged in facebook app or web app. User still needs to logout from facebook app himself/herself.
  • kaizen
    kaizen about 4 years
    Hi, what does loginManager.logOut() return upon success and failure? and does it need a try catch?
  • Thanveer Shah
    Thanveer Shah over 3 years
    Did anyone figiure out how to solve this ?