You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native iOS Firebase匿名认证[auth/internal-error]问题求助

React Native iOS Firebase匿名认证[auth/internal-error]问题排查与解决需求

生产环境中,5%的用户调用auth().signInAnonymously()时触发[auth/internal-error]错误,提示“An internal error has occurred, please try again”,仅生产环境出现该问题,开发环境无异常。

问题详情

应用Firebase认证已按官方文档配置,开发和生产环境使用两个独立Firebase项目,共用bundle identifier,通过AppDelegate.mm加载对应环境的GoogleService-Info.plist文件。仅生产环境出现该错误,影响5%的用户。

额外信息

  • 多数用户可正常完成认证;
  • 用户量激增时错误频率明显上升,疑似高并发相关;
  • 部分用户重试多次或几小时后重启应用可成功认证;
  • 德国用户出现该错误的频率最高;
  • 多数用户遇到错误后无法立即成功,少数需重试20次或次日重启才行;
  • 用户遇到auth/network-request failed错误时大多能成功认证。

已排查内容

  • 联系GCP团队检查日志,Identity Toolkit无服务器错误记录;
  • 无法在开发或生产环境的iOS测试设备上复现问题;
  • 移除AppCenter和CodePush后问题未改善;

相关代码

App.tsx

// App.tsx

useEffect(() => {
  const subscriber = auth().onAuthStateChanged(async user => {
    if (initializing) {
      setTimeout(() => RNBootSplash.hide({ fade: true }), 300)
      setInitializing(false)
    }

    if (user) //  Do some configuration
  })

  return () => {
    subscriber()
  }
}, [])

if (initializing) return null // render nothing until firebase auth is initialized.

// Wrappers are redux, persistor, styled-components theme provider, navigation etc...
return <Wrappers> <AppContent /> </Wrappers>

AppContent.tsx

// AppContent.tsx

useEffect(() => {
  const configureAuthUser = async () => {
    try {
      const result = await auth().signInAnonymously()
      const user = result.user
      if (user) {
        dispatch(fetchMeUser())
        analytics.track(events.app.authentication_success(user.uid))
      } else {
        analytics.report('user is null in app configure auth user')
        analytics.track(events.app.authentication_user_null())
      }
    } catch (error: any) {
      analytics.report('error configuring auth user: ' + error.message)
      analytics.track(events.app.authentication_failed(error.message))
    }
  }

  configureAuthUser()
}, [])

package.json

// package.json

...
"@react-native-firebase/analytics": "^18.7.2",
"@react-native-firebase/app": "^18.7.2",
"@react-native-firebase/auth": "^18.7.2",
"@react-native-firebase/crashlytics": "^18.7.2",
"@react-native-firebase/database": "^18.7.2",
"@react-native-firebase/messaging": "^18.7.2",
"@react-native-firebase/storage": "^18.7.2",
...

Podfile

// Podfile

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '13'
prepare_react_native_project!
inhibit_all_warnings!
use_frameworks! :linkage => :static

target '....' do
  use_modular_headers!
  config = use_native_modules!
  flags = get_default_flags()

  $RNFirebaseAsStaticFramework = true

  pod 'MLKitCommon', :podspec => 'MLKitCommon.podspec.json'
  pod 'MLKitVision', :podspec => 'MLKitVision.podspec.json'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec', :modular_headers => false

  use_react_native!(
    :path => config[:reactNativePath],
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target '.....' do
    inherit! :complete
    # Pods for testing
  end
  
  post_install do |installer|
    react_native_post_install(
      installer,
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
        config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
        config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
      end
    end
  end
end

AppDelegate.mm

// AppDelegate.mm
#import "AppDelegate.h"
#import "RNBootSplash.h"
#import <Firebase.h>
#import <React/RCTBundleURLProvider.h>
#import <AppsFlyerLib/AppsFlyerLib.h>
#import <AppsFlyerAttribution.h>

#import <AuthenticationServices/AuthenticationServices.h>
#import <SafariServices/SafariServices.h>
#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Here is where we pick from Production and Development GoogleService-Info.plist
  NSString *filePath;
#ifdef DEBUG
  NSLog(@"[FIREBASE] Development mode.");
  filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Development"];
#else
  NSLog(@"[FIREBASE] Production mode.");
  filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist" inDirectory:@"Production"];
#endif

  FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath];
  [FIRApp configureWithOptions:options];
  
  [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
  [FBSDKApplicationDelegate.sharedInstance initializeSDK];
  
  self.moduleName = @"....";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feature is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
  return true;
}

- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initProps:(NSDictionary *)initProps {
  UIView *rootView = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
  [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // ⬅️ initialize the splash screen
  return rootView;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [[AppsFlyerLib shared] registerUninstall:deviceToken];
}

// Deep linking
// Open URI-scheme for iOS 9 and above
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *) options {
  [[AppsFlyerAttribution shared] handleOpenUrl:url options:options];
    return YES;
}

// Open Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable)) restorationHandler {
    [[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:restorationHandler];
    return YES;
}

@end

期望结果

解决该匿名认证错误,确保所有用户都能正常完成认证。

内容的提问来源于stack exchange,提问作者Get Schwifty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 14:14:55