首页 > 解决方案 > react-native ios项目中的Firebase身份验证问题

问题描述

我们已经向商店发布了本机 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:

很难从错误消息中找出到底出了什么问题。

当我们配置 react-native IOS 应用程序以使用登录到其他 Firebase 项目(用于开发目的)时,谷歌登录工作正常。在这两种情况下,IOS 捆绑包 ID 都是相同的。

所有与应用程序相关的代码和配置都根据react-native-firebase 库文档完成。

在新创建的具有相同 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 身份验证运行良好。

所以它看起来不像反应本机应用程序代码中的问题,而是与捆绑ID相关的问题。同时,具有相同捆绑 ID 的 IOS 原生应用运行良好。

帮我找出 Firebase 身份验证不起作用的原因?

标签: firebasereact-nativefirebase-authentication

解决方案


我遇到了同样的问题,但我没有找到任何关于此的文档。所以这是我的经验。

我的开发环境也有一个 Firebase 项目,一切正常。我为我的 prod 环境制作了另一个,Firebase-auth 在ios上系统地返回了错误“发生内部错误,请重试” 。

因此,我更改了 prod 项目(当然还有 Xcode)的 bundle id,问题就消失了。

这是有道理的,在android上你不能有相同的包名/sha证书。在 ios 上,相同的限制被合并到唯一的 bundle id 上。但是如果像在android上发生错误会更好。

总而言之:Firebase 项目仅使用一个捆绑包 ID!


推荐阅读