Expo Google 身份验证不适用于生产

时间:2021-07-15 19:23:48

标签: expo

我按照文档 https://docs.expo.io/guides/authentication/#google 中的代码在我的应用上实现了 Expo 身份验证。

在本地使用 Expo 客户端,它在 IOS 模拟器和 Web 浏览器中工作正常,但是当我构建应用程序 (expo build android) 并在我的 Android 手机上尝试时,Google弹出窗口来了,我输入了我的 ID,它让我回到登录页面,但什么也没发生。

我发出了一些警报以了解发生了什么,但我什至没有得到任何警报,useEffect 没有触发,responseGoogle 似乎没有改变。

const [requestGoogle, responseGoogle, promptAsyncGoogle] =
    Google.useAuthRequest({
      expoClientId:
        "my_id",
      androidClientId:
        "my_id,
      webClientId:
        "my_id",
    });

  useEffect(() => {
    alert("useEffect fired (Google)");
    if (responseGoogle?.type === "success") {

      const { authentication } = responseGoogle;
       
      // success
      alert("success : "+JSON.stringify(responseGoogle));
      
      // some code to check and log the user... 

    } else {
      alert('no success : '+JSON.stringify(responseGoogle));
    }
  }, [responseGoogle]);

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

显然这是一个已知错误,所以这里不是答案,而是 expo-google-sign-in 的替代方法:

 import * as GoogleSignIn from "expo-google-sign-in";
 async function loginWithGoogle() {    
    try {
      await GoogleSignIn.askForPlayServicesAsync();
      const { type, user } = await GoogleSignIn.signInAsync();
      if (type === "success") {
        alert(JSON.stringify(user));
      }
    } catch ({ message }) {
      toast.show("Erreur:" + message);
      alert("login: Error:" + message);
    }
  }