[英]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?简单来说,如何使用 react-native-fbsdk 提供的 LoginManager 登出?
If we look the code inside that LoginManager provided by react-native-fbsdk, we find this part regarding logout :如果我们查看 react-native-fbsdk 提供的 LoginManager 中的代码,我们会发现这部分是关于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.
如果我调用LoginManager.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.).我在想这是因为如果您检查
react-native-fbsdk
LoginButton
上的默认LoginButton
onLogoutFinished
prop 不会传递有关注销操作的任何参数(成功、失败等)。 This means you can assume that its gonna happen without any problem since facebook itself assumed that.这意味着你可以假设它会毫无问题地发生,因为 facebook 本身就是这么认为的。 Default
LoginButton
listens for events to run onLogoutFinished
function.默认
LoginButton
侦听事件以运行onLogoutFinished
函数。 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.实际上,成功登录后, acsessToken 变为空。因此,在调用 loginmanager.logout() 后,您可以使用 AccessToken.getCurrentAccessToken() 检查访问令牌,如果它为空,则您可以放心地假设注销已成功发生。
LoginManager.logOut();
const token = await AccessToken.getCurrentAccessToken();
if(_.isEmpty(token) {/* your code for doing logout related actions */}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.