gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:34:05 24 4
gpt4 key购买 nike

作为问题,对于在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com