【问题标题】:flutter firebaseauth signout() not working颤动的firebaseauth signout()不起作用
【发布时间】:2020-10-11 20:25:45
【问题描述】:

我正在使用 firebase auth 注销方法,但它似乎无法正常工作。当我单击注销按钮时,它应该注销当前用户。但是,这样做之后,控制台并没有表明 firebase auth 注销方法实际上正在工作,没有!

应用程序有一个系统,如果用户在线,那么他们将始终在打开应用程序时被重定向到主页,除非他们从应用程序注销(他们将被重定向到登录页面)。并且应用程序在打开应用程序时总是将我重定向到主页,因此很明显,即使在我点击注销按钮后,firebase auth 注销方法也不起作用

这是我的注销方法,它在 Authentication 类中

FirebaseAuth _auth = FirebaseAuth();

logOut() async {
    return await _auth.signOut();
}

这是回调,当我单击注销按钮时会调用 logOutCurrentUser 函数

Authentication authentication = Authentication();
  
  logOutCurrentUser(BuildContext context) {
    try {
      authentication.logOut();
      Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LoginSignupToggle(true)), (route) => false);
    }
    catch (e) {
      print(e.toString());
    }
  }

总而言之,即使在我点击注销按钮后,FirebaseAuth.instance.currentUser() 似乎仍然不为空,我希望它在注销后为空

我已经尽可能多地尝试寻找答案,但似乎没有什么对我有用

【问题讨论】:

标签: firebase flutter dart firebase-authentication


【解决方案1】:

我的猜测是您的退出已中止,因为您没有等待它完成。由于您的logOutasync,因此在调用它时需要使用await

await authentication.logOut();
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder: (context) => LoginSignupToggle(true)), (route) => false);

【讨论】:

    猜你喜欢
    • 2021-03-03
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 2018-11-17
    • 1970-01-01
    • 2021-03-15
    相关资源
    最近更新 更多