React Native Expo Firebase Auth 不适用于版本 9
React Native Expo Firebase Auth not working on Version 9
我得到一个错误“_config.firebase.auth 不是一个函数。(在‘_config.firebase.auth()’中,‘_config.firebase.auth’是未定义的)
提交注册表时出现此错误。
我运行 Firebase 版本 9.6.5
谁能在我的 config.js 和 RegScreen.js 文件中找出我哪里出错了?
import firebase from 'firebase/compat/app';
import '@firebase/auth';
import '@firebase/firestore';
const firebaseConfig = {
apiKey: '',
authDomain: 'to-do-weather.firebaseapp.com',
databaseURL: 'https://DATABASE_NAME.firebaseio.com',
projectId: 'to-do-weather',
storageBucket: 'to-do-weather.appspot.com',
messagingSenderId: '',
appId: '',
};
let app;
if (firebase.apps.length === 0) {
app = firebase.initializeApp(firebaseConfig)
} else {
app = firebase.app();
}
export { firebase };
const onRegPress = () => {
if (password !== confirmPassword) {
alert("Passwords don't match.")
return
}
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then((response) => {
const uid = response.user.uid
const data = {
id: uid,
email,
fullName,
};
const usersRef = firebase.firestore().collection('users')
usersRef
.doc(uid)
.set(data)
.then(() => {
navigation.navigate('Home', {user: data})
})
.catch((error) => {
alert(error)
});
})
.catch((error) => {
alert(error)
});
}
如果您尝试使用 namespaced
语法,那么您还必须导入所有 Firebase 服务的 compat
版本。尝试将导入更改为:
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
// add /compat ^
compat 版本最终会被删除,所以我建议更新您的代码并遵循 documentation
中提到的新语法
我得到一个错误“_config.firebase.auth 不是一个函数。(在‘_config.firebase.auth()’中,‘_config.firebase.auth’是未定义的)
提交注册表时出现此错误。
我运行 Firebase 版本 9.6.5
谁能在我的 config.js 和 RegScreen.js 文件中找出我哪里出错了?
import firebase from 'firebase/compat/app';
import '@firebase/auth';
import '@firebase/firestore';
const firebaseConfig = {
apiKey: '',
authDomain: 'to-do-weather.firebaseapp.com',
databaseURL: 'https://DATABASE_NAME.firebaseio.com',
projectId: 'to-do-weather',
storageBucket: 'to-do-weather.appspot.com',
messagingSenderId: '',
appId: '',
};
let app;
if (firebase.apps.length === 0) {
app = firebase.initializeApp(firebaseConfig)
} else {
app = firebase.app();
}
export { firebase };
const onRegPress = () => {
if (password !== confirmPassword) {
alert("Passwords don't match.")
return
}
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then((response) => {
const uid = response.user.uid
const data = {
id: uid,
email,
fullName,
};
const usersRef = firebase.firestore().collection('users')
usersRef
.doc(uid)
.set(data)
.then(() => {
navigation.navigate('Home', {user: data})
})
.catch((error) => {
alert(error)
});
})
.catch((error) => {
alert(error)
});
}
如果您尝试使用 namespaced
语法,那么您还必须导入所有 Firebase 服务的 compat
版本。尝试将导入更改为:
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
// add /compat ^
compat 版本最终会被删除,所以我建议更新您的代码并遵循 documentation
中提到的新语法