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
相关产品推荐
相关产品推荐

