【发布时间】:2020-11-22 07:59:15
【问题描述】:
我们已经向商店发布了原生 IOS 和 Android 应用程序。 目前即将完成 react-native 版本以替换原生应用程序。 React-native 应用程序使用与原生相同的 firebase 项目。 Firebase 身份验证适用于原生应用和 react-native android 应用。 在 react-native ios 上,我们无法使用 google 登录。
错误日志:
错误:[auth/internal-error] 发生内部错误,请重试。 NativeFirebaseError: [auth/internal-error] 发生内部错误,请重试。 onGoogleButtonPress$@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:98254:89 tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:28586:23 调用@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:28759:32 tryCatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:28586:23 调用@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:28659:30 http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:28669:21 tryCallOne@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3475:16 http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:3576:27 _callTimer@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30574:17 _callImmediatesPass@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30613:17 callImmediates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:30830:33
很难从错误消息中找出到底出了什么问题。
当我们配置 react-native IOS 应用程序以使用登录到其他 Firebase 项目(用于开发目的)时,谷歌登录工作正常。 在这两种情况下,IOS bundle id 都是相同的。
所有应用相关的代码和配置都按照react-native-firebase library docs完成。
在新创建的具有相同 IOS 捆绑包 ID 且未添加任何其他辅助功能代码的新创建的 react-native 项目上也可以重现该问题。
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Button,
StatusBar,
} from 'react-native';
import {Colors} from 'react-native/Libraries/NewAppScreen';
import {GoogleSignin} from '@react-native-community/google-signin';
import auth from '@react-native-firebase/auth';
const App: () => React$Node = () => {
async function onGoogleButtonPress() {
const {idToken} = await GoogleSignin.signIn();
const googleCredential = auth.GoogleAuthProvider.credential(idToken);
return auth().signInWithCredential(googleCredential);
}
GoogleSignin.configure({
webClientId:
'<PASTE CLIEND ID FROM GoogleService-Info.plist>',
});
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<View style={styles.body}>
<Button
title="Google Sign-In"
onPress={() =>
onGoogleButtonPress().then(() =>
console.log('Signed in with Google!'),
)
}
/>
</View>
</ScrollView>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
body: {
backgroundColor: Colors.white,
},
});
export default App;
当在生产 Firebase 实例上添加具有其他包 ID 的新 IOS 项目并将这些包设置为 react-native 应用程序时,Firebase 身份验证运行良好。
所以它看起来不像 react native-app 代码中的问题,而是与 bundle id 相关的问题。同时,具有相同捆绑 ID 的 IOS 原生应用运行良好。
帮我找出 Firebase 身份验证不起作用的原因?
【问题讨论】:
-
通常当我无法从 JavaScript 控制台错误中获得太多信息时,我会查看 Xcode 控制台的输出。可能没有正确安装firebase。确保在 React Native 项目 ios 文件夹中运行
pod install。还要检查您的 GoogleServices-info.plist 是否与 info.plist 位于同一目录中,并且您使用 Xcode 添加了该文件,而不仅仅是将其放在 RN ios 文件夹中。 -
您没有正确捕获错误,请在 onGoogleButtonPress 中使用 try/catch 并检查您遇到的错误。那么也许我们可以提供帮助
-
感谢 Jack 和 Skorp 的帮助,Pod 安装完成,我们使用了正确的 GoogleServices-info.plist,它与 info.plist 位于同一目录中,并使用 Xcode 添加文件到“项目" 启用了复制复选框的上下文菜单。 xcode 内部的错误日志也不提供任何其他信息。
-
嗨,Scorp,感谢您的评论。遗憾的是,捕捉错误并没有提供额外的信息。
标签: firebase react-native firebase-authentication