简体   繁体   中英

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

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?

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.

For me, this works:

import { LoginManager } from 'react-native-fbsdk'
LoginManager.logOut()

Actually after successfully login out the acsessToken becomes null.So after calling loginmanager.logout() you can check the accesstoken with AccessToken.getCurrentAccessToken() and if it comes null then you can safely assume that the logout has happened successfully.

LoginManager.logOut();
const token = await AccessToken.getCurrentAccessToken();
if(_.isEmpty(token) {/* your code for doing logout related actions */}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM