在没有"弹出"项目的情况下,在expo(create-react-native-app)中使用Firebase google身份验证的任何方法

Noe*_*ova 5 google-authentication firebase google-play-services expo create-react-native-app

作为问题,对于使用gobase in firebase登录需要设置google-service但是如果使用create-react-native-app创建新的react-native项目则不会有"android"或"ios"文件夹(接受使用"弹出" ")所以,有人对我有建议吗?但是我也不知道如何在我的项目中设置google-service(甚至我"弹出"项目).

Joe*_*ddy 10

@brentvatne的回答有点过时了.以下是我在Expo v27上的工作方式

重要的一点:您可以使用这些说明获取客户ID .

只需从谷歌页面上的项目下拉列表中选择您的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);
  }
};
Run Code Online (Sandbox Code Playgroud)


bre*_*tne 4

无需对 android 或 ios 文件夹进行任何更改即可支持 Google 在使用 Expo 构建的应用程序上使用 firebase 登录。

  1. 按照Expo 文档上的配置 Google 身份验证指南进行操作
  2. 使用 Expo 的使用 Firebase 指南中描述的方法,其中描述了如何使用 Facebook 进行身份验证,并在需要时更换 Google。

  • @NoerNova - 从Expo的api返回的响应中,您有一个带有`idToken`,`accessToken`和一些其他属性的对象(https://github.com/expo/expo-sdk/blob/d152d47f240aadc1618e13a2ab3832411c62e9b8/src/ Google.js#L18-L36) - 您需要获取 `idToken` 和 `accessToken` 并将它们传递到您的 `googleAuthenticate` 函数中,如下所示:https://gist.github.com/brentvatne/46449731ae852a14ce321e14f0f19187 (3认同)