从Firebase中删除用户帐户后,从所有设备注销。

huangapple go评论74阅读模式
英文:

Logout from all devices as user account deleted from firebase flutter

问题

我有应用程序的网页和移动版本。我在移动和网页上都使用相同的帐户登录。当我在移动设备上删除我的帐户时,我仍然可以在网页上执行所有操作。那么,当用户帐户被删除时,如何将用户从所有设备注销?

英文:

I have web and mobile versions of the app. I am logged in with the same account on mobile and the web. When I deleted my account on mobile, I was able to perform all the actions on the web. So, how can I log out the user from all the devices when the user account is deleted?

答案1

得分: 1

Firebase没有提供这样的功能,但您可以按照以下方法操作。

_checkIfAccountIsDeleted() async {
  try {
    IdTokenResult? idTokenResult =
        await FirebaseAuth.instance.currentUser?.getIdTokenResult(true);

    if (idTokenResult == null || idTokenResult.token == null) {
      print("用户已删除");
      //   FirebaseAuth.instance.signOut();
      // 在这里执行注销操作...
    } else {
      print("用户可用");
    }
  } catch (er) {
    print("用户已删除");
    //   FirebaseAuth.instance.signOut();
  }
}

我已经检查过,在我的情况下它可以正常工作。

英文:

Firebase does not provide such feature but you can follow the trick as below.

 _checkIfAccountIsDeleted() async {
    try {
      IdTokenResult? idTokenResult =
          await FirebaseAuth.instance.currentUser?.getIdTokenResult(true);

      if (idTokenResult == null || idTokenResult.token == null) {
        print("User is deleted");
        //   FirebaseAuth.instance.signOut();
        // do logout stuff here...
      } else {
        print("User is available");
      }
    } catch (er) {
      print("User is deleted");
      //   FirebaseAuth.instance.signOut();
    }
  }

I have checked it and it is working fine in my case.

huangapple
  • 本文由 发表于 2023年5月29日 14:03:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76354989.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定