javascript - 无法将新文档设置为 Firestore 中的集合
问题描述
我已经尝试了将新文档设置到 Firestore 的各种不同方式,但无法实现。我没有收到任何错误,但数据永远不会发布。我确定我错过了一些简单的东西,但我就是不知道它是什么
import styles from '../../styles/createPost.module.css'
import firebase from '../../firebase/initFirebase'
import { useSession } from 'next-auth/client'
export default function CreatePostButton(props) {
const [session] = useSession()
const time = Date.now()
const today = new Date(time)
const sendData = async() => {
if (props.postContent) {
await firebase.firestore().collection("postData").doc()
.set({
postAuthor: session.user.name,
path: "/cidProfile",
profileImg: session.user.image,
postText: props.postText,
postContent: props.postContent.name,
postTime: today.toUTCString(),
reactionsTotal: 1,
isliked: false,
commentCount: 0,
shareCount: 0,
sharable: props.shareable,
}).then(alert('Your Post was Sent!'))
} else {
await firebase.firestore().collection("postData").doc()
.set({
postAuthor: session.user.name,
path: "/meow",
profileImg: session.user.image,
postText: props.postText,
postTime: today.toUTCString(),
reactionsTotal: 1,
isliked: false,
commentCount: 0,
shareCount: 0,
sharable: props.shareable,
}).then(alert(props.postText))
}
}
return (
<div className={styles.postButtonDiv}>
<button className={styles.postButton} onClick={sendData} disabled={!props.disableButton}>Post</button>
</div>
)
}
解决方案
语法似乎很好,我怀疑这要么是安全规则问题,要么是 Firebase 客户端未启动的问题。这些错误自然会被记录或在您的环境控制台中抛出错误。
推荐阅读
- php - php中的多维数组(具有相同的键不同的值)如何为键创建一个新名称?
- php - 如何为 Apache 编写 .htaccess 文件以附加 PHP(如果未提供)并使用编写良好的 404 页面
- python - python正则表达式匹配点和括号
- javascript - 无法使用链接更改机器人的头像
- python - 在 PyTorch 中使用 BatchNorm 的准确率非常低
- mysql - 使用 Null 值将表连接到自身
- ios - Xcode 新更新 - 重用标识符问题
- logging - 在 Dart 中创建一个中间件控制器来处理对 Aqueduct 的所有请求
- flutter - 为什么在 Pubspec.lock 中颤振 sdk 的版本低于:“0.0.0”?如何安全地锁定一个颤振版本?
- reactjs - React.memo 和 withRouter