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

React Native中Firebase邮箱密码认证出现auth.tenantId未定义错误

解决Firebase邮箱密码认证中TypeError: undefined is not an object (evaluating 'auth.tenantId')错误

问题原因

你的代码中Firebase Auth实例的导入方式不匹配:在Firebase配置文件里,你用的是命名导出export const auth,但在注册页面中却用了默认导入import auth from '../../../../firebase/firebase',这会导致auth变量实际为undefined,调用createUserWithEmailAndPassword时自然会抛出auth.tenantId无法读取的错误。

修复步骤

修改注册页面的auth导入语句,改用命名导入,和配置文件的导出方式对应:

import { createUserWithEmailAndPassword } from 'firebase/auth';
import { auth } from '../../../../firebase/firebase'

const handleFirebase = () => {
    createUserWithEmailAndPassword(auth, email, password)
      .then(response => { console.log(response.user); })
      .catch((error) => (console.error(error)));
}

额外验证点

  • 可以先在handleFirebase函数内添加console.log(auth),确认导入后的auth是一个有效的Firebase Auth对象,而非undefined。
  • 你的Firebase配置文件中getAuth(app)的初始化逻辑是正确的,无需修改。

内容的提问来源于stack exchange,提问作者en garcon

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 08:15:34