[英]Firebase V9 Online Status
我正在尝试在 React 中将一些 Firebase v8 代码重新配置为 firebase v9 ... 在登录/注册页面上,我想将在线状态更改为 true。
我不确定这行代码是否会与更新的变量名有很大不同或完全相同。 这可能是一个非常简单的问题(希望如此)。 我知道在 v9 中,很多这些类型的东西都通过 firebase 库中已经可用的 function 的导入语句进行了重组。 IDK 如果这是其中之一......:/。 谢谢你的时间。 如果我需要包含更多代码以使其有意义,请提前告诉我...
旧(工作)v8 代码:
变量:
关注下面的行:“// set online to be true”...在登录/注册页面中:
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)
}
})
有一个顶级 function updateDoc()
来更新文档:
import { updateDoc, doc } from "firebase/firestore";
const docRef = doc(db, "users", res.user.uid)
await updateDoc(docRef, { online: true });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.