firebase - 在没有 "eject"项目的情况下在博览会(create-react-native-app)中使用 Firebase google 身份验证的任何方法

标签 firebase google-authentication google-play-services expo create-react-native-app

作为问题,对于在 firebase 中使用 google 登录,需要设置 google-service 但如果您使用 create-react-native-app 创建新的 React-native 项目,则不会有“android”或“ios”文件夹(接受使用“弹出”)那么,有人对我有建议吗? 但是我也不知道如何在我的项目中设置 google-service (即使我“弹出”该项目)。

最佳答案

@brentvatne 的答案有点过时了。以下是我如何在 Expo v27 上使用它

重要一点:您可以使用 these instructions 获取您的客户端 ID .

只需从 Google 页面上的项目下拉列表中选择您的 Firebase 应用即可。

const _loginWithGoogle = async function() {
  try {
    const result = await Expo.Google.logInAsync({
      androidClientId:"YOUR_ANDROID_CLIENT_ID",
      iosClientId:"YOUR_iOS_CLIENT_ID",
      scopes: ["profile", "email"]
    });

    if (result.type === "success") {
      const { idToken, accessToken } = result;
      const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);
      firebase
        .auth()
        .signInAndRetrieveDataWithCredential(credential)
        .then(res => {
          // user res, create your user, do whatever you want
        })
        .catch(error => {
          console.log("firebase cred err:", error);
        });
    } else {
      return { cancelled: true };
    }
  } catch (err) {
    console.log("err:", err);
  }
};

关于firebase - 在没有 "eject"项目的情况下在博览会(create-react-native-app)中使用 Firebase google 身份验证的任何方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44616596/

相关文章:

ios - 从 Firebase 数据拉取初始化类

oauth-2.0 - 错误 400 : invalid_scope "https://www.googleapis.com/auth/chat.bot"

java - 如何使用两个jsons使用 secret 来在java中向google进行身份验证

android - 应用程序在使用 Google Play 服务时遇到问题。请再试一次

android - Android 中的 Google 登录按钮错误

android - 从 Firebase 读取多个值并放置在折线图中

javascript - 如何修复参数 "documentPath"的值不是有效的资源路径?

android - Playstore 中的 Apk 上传错误 - 64 位警告

android - 是否可以将 firebase 自定义属性分析设置为数组?

javascript - googleapis TypeError : authClient. 请求不是 nodejs 中的函数