Google 第二次登录 React native 后登录页面不显示

Google Sign In Page Not Display After Second Login React native

我通过本机反应开发应用程序并使用 rnfirebase 连接 google firebase 身份验证。我有这样的 google 按钮登录代码。

const _signIn = async () => {
setInitializing(true);
try {
  await GoogleSignin.hasPlayServices();
  const userInfo = await GoogleSignin.signIn();
  const credential = auth.GoogleAuthProvider.credential(
    userInfo.idToken,
    userInfo.accessToken,
  );
  return auth()
    .signInWithCredential(credential)
    .then(response => {
      const uid = response.user.uid;
      const data = {
        uid: uid,
        email: userInfo.user.email,
        fullname: userInfo.user.name,
        bio: 'I am ok ..',
        username: uid.substring(0, 8),
      };
      const usersRef = firestore().collection('users');
      usersRef
        .doc(uid)
        .get()
        .then(firestoreDocument => {
          if (!firestoreDocument.exists) {
            usersRef
              .doc(data.uid)
              .set(data)
              .then(() => {
                RNRestart.Restart();
              })
              .catch(error => {
                setInitializing(false);
                Alert.alert(JSON.stringify(error.message));
              });
          } else {
            setInitializing(false);
          }
        })
        .catch(error => {
          Alert.alert(JSON.stringify(error.message));
          console.log('Error getting document:', error);
        });
    });
} catch (error) {
  if (error.code === statusCodes.SIGN_IN_CANCELLED) {
    setInitializing(false);
    Alert.alert('Sign in canceled');
  } else if (error.code === statusCodes.IN_PROGRESS) {
    setInitializing(false);
    Alert.alert('Signin in progress');
  } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
    setInitializing(false);
    Alert.alert('PLAY_SERVICES_NOT_AVAILABLE');
  } else {
    setInitializing(false);
    Alert.alert(JSON.stringify(error.message));
  }
} };

在 IOS 中,当我以新用户/注册用户身份登录时,应用程序始终显示 google 登录页面。所以我可以选择我想使用的帐户。像这样:

但在Android、Google登录页面显示首次用户登录。之后,如果用户从应用程序注销,他想通过 google 按钮再次登录,用户直接使用最后一个 gmail 转到主应用程序。所以在 android 中,如果我之前登录过,我将无法切换/使用其他帐户。

每次用户在 android 中通过 google 按钮登录时,如何显示 google 登录页面? 谢谢。

在你的注销功能中,如果用户通过Google登录,你需要实现google注销功能:

GoogleSignin.signOut();

更好的方法是同时撤销访问权限,因此完整的注销功能可以是:

await GoogleSignin.revokeAccess();

await GoogleSignin.signOut();