使Flutter应用强制用户选择具有FirebaseAuth和GoogleSignInAuthentication的帐户

时间:2019-03-17 10:58:50

标签: flutter firebase-authentication google-signin

我想强制用户在登录期间选择其帐户之一。有什么办法吗?我没有找到任何类似prompt=select_account+consent的配置。

现在,使用这些代码,在用户注销并再次尝试登录后,它将自动使用所选帐户登录,没有窗口显示供用户选择帐户。

pubspec.yaml

firebase_auth: ^0.8.1+4
google_sign_in: ^3.2.4

登录部分

GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;

final AuthCredential credential = GoogleAuthProvider.getCredential(
  accessToken: googleAuth.accessToken,
  idToken: googleAuth.idToken,
);
user = await _auth.signInWithCredential(credential);

退出部分

await FirebaseAuth.instance.signOut();
GoogleSignIn _googleSignIn = GoogleSignIn();
await _googleSignIn.signOut();

2 个答案:

答案 0 :(得分:1)

在退出之前使用GoogleSignInAccount.disconnect()撤消以前的身份验证:

await _googleSignIn.disconnect();
await FirebaseAuth.instance.signOut();

答案 1 :(得分:0)

一种简单的解决方法:- 在退出方法中,只需使用

_auth.signOut();

现在在Google登录包中,在google_sign_in.dart中

 Future<GoogleSignInAccount> signIn() {
    final Future<GoogleSignInAccount> result =
        _addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: false);
    bool isCanceled(dynamic error) =>
        error is PlatformException && error.code == kSignInCanceledError;
    return result.catchError((dynamic _) => null, test: isCanceled);
  }

找到上述方法并将canSkipCall参数设置为false

final Future<GoogleSignInAccount> result =
        _addMethodCall(GoogleSignInPlatform.instance.signIn, canSkipCall: false);

这将使您每次尝试登录时都能选择一个用户

相关问题