我正在尝试重新配置一些Firebase v8代码,使其成为firebase v9中的React.在登录/注册页面上,我希望将联机状态更改为true。
我不确定这一行代码是否会有很大不同,或者与更新后的变量名称完全相同。这可能是一个非常简单的问题(希望如此)。我知道,在v9中,许多这类东西都是用一个函数的导入语句进行重构的,这个函数已经在firebase库中可用。如果这是其中之一..。*耽误您时间,实在对不起!如果我需要包括更多的代码以便有意义的话请提前告诉我.
旧(工作) v8代码:
变量:
专注于下面一行:"// set online to true“...within登录/注册页面:
try {
// login
const res = await projectAuth.signInWithEmailAndPassword(email, password)
//set online to be true
await projectFirestore.collection('users').doc(res.user.uid)
.update({ online: true })
// dispatch login action
dispatch({ type: 'LOGIN', payload: res.user })
if (!isCancelled) {
setIsPending(false)
setError(null)
}
} 我的v9代码:
变量:
try {
// login
await signInWithEmailAndPassword(auth, email, password)
.then((res) => {
// dispatch login action
dispatch({ type: 'LOGIN', payload: res.user })
//set online to be true
await projectFirestore.collection('users').doc(res.user.uid)
.update({ online: true })
if (!isCancelled) {
setIsPending(false)
setError(null)
}
})发布于 2022-05-27 19:45:06
有一个顶级函数updateDoc()来更新文档:
import { updateDoc, doc } from "firebase/firestore";
const docRef = doc(db, "users", res.user.uid)
await updateDoc(docRef, { online: true });https://stackoverflow.com/questions/72410253
复制相似问题