首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在expo中使用Firebase google身份验证(create-react-native-app)而不使用"eject“项目的任何方法

在expo中使用Firebase google身份验证(create-react-native-app)而不使用"eject“项目的任何方法
EN

Stack Overflow用户
提问于 2017-06-18 23:29:48
回答 2查看 9.1K关注 0票数 8

作为一个问题,在firebase中登录google需要设置google-service,但如果你用create- react-native -app创建一个新的react-native项目,将没有"android“或"ios”文件夹(接受使用的"eject"),所以,有人给我一个建议吗?然而,我也不知道如何在我的项目中设置google-service (甚至我也“弹出”了这个项目)。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-19 02:43:21

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

  1. 遵循世博会Using Firebase guide中描述的方法,其中描述了如何在脸书上进行身份验证,并在需要的地方替换掉谷歌。
票数 4
EN

Stack Overflow用户

发布于 2018-05-18 03:20:28

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

重要提示:您可以使用these instructions获取客户端ids。

只需从google页面的项目下拉列表中选择您的firebase应用程序即可。

代码语言:javascript
复制
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);
  }
};
票数 20
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44616596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档