在Flutter Firebase auth中注销不同类型的帐户的按钮

发布于 2025-02-13 12:20:51 字数 799 浏览 1 评论 0原文

我有一个flutter应用程序,其中包含多个选项(电子邮件和密码,Google帐户,电话号码)。用户登录应用程序后,他将有一个抽屉。 该抽屉里有一个签名按钮,当用户按下时应该签名并将其发送回注册页面。所以我一直在使用firebase auth的登录实例 await firebaseauth.instance.signout();

,但是由于我在选项中添加了Google签名,因此我开始面临一个问题,即Google签名,我会nee dto do do do连接用户first 等待googlelesignin .disconnect(); 因此,我将这一行添加到登录功能中,以至于这样:

  Future<void> SignOut() async {
 await googleSignIn.disconnect();
 await FirebaseAuth.instance.signOut();
 Navigator.pushAndRemoveUntil(
   context,
   MaterialPageRoute(
     builder: (BuildContext context) => AuthPage(),
   ),
       (route) => false,
 );}

当用户使用Google登录时,此按钮可以正常工作,但是如果他使用不同的方法登录,则会出现错误:

未经治疗的异常:platformException(状态,无法断开连接。,null,null)

如何使用一个按钮处理不同类型的用户签名?

I have a flutter app with multiple sign in options (Email and password, Google account, phone number). Once the user sign in to the application, he will then have a drawer.
There is a Sign out button inside this drawer which should sign the user out when he press it and send him back to the signup page. So I have been using the sign out instance from firebase auth
await FirebaseAuth.instance.signOut();

But since I added the google sign in options I started facing a problem which is that for google sign out, I nee dto disconnect the user first await googleSignIn.disconnect();
So I added this line to the sign out function to be like this:

  Future<void> SignOut() async {
 await googleSignIn.disconnect();
 await FirebaseAuth.instance.signOut();
 Navigator.pushAndRemoveUntil(
   context,
   MaterialPageRoute(
     builder: (BuildContext context) => AuthPage(),
   ),
       (route) => false,
 );}

This button works fine when the user sign in with google but if he signs in with different method then an error will be thrown:

Unhandled Exception: PlatformException(status, Failed to disconnect., null, null)

How can I handle different type of users signout with one button?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2025-02-20 12:20:51
Future<void> SignOut() async {
if (googleSignIn.currentUser != null){
  await googleSignIn.disconnect();
  await FirebaseAuth.instance.signOut();}
else{
  await FirebaseAuth.instance.signOut();}
Future<void> SignOut() async {
if (googleSignIn.currentUser != null){
  await googleSignIn.disconnect();
  await FirebaseAuth.instance.signOut();}
else{
  await FirebaseAuth.instance.signOut();}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文