javascript - Firebase 未使用 .doc 上传到 Firestore
问题描述
我正在尝试使用firebase和stripe根据此处找到的源代码在我的网站上设置付款:https ://github.com/firebase/functions-samples/tree/master/stripe 我已经尝试重置我的规则firestore 和实时数据库,但我一直卡在 .snapshot 上。我查看了调试器,currentUser.uid 不为空,但它没有在数据库中创建新条目。对此的任何帮助将不胜感激!第一次使用firebase所以我有点迷茫。目前,我的规则文件与 github repo 中链接的文件相同。
firebase.auth().onAuthStateChanged((firebaseUser) => {
if (firebaseUser) {
currentUser = firebaseUser;
firebase
.firestore()
.collection('stripe_customers')
.doc(currentUser.uid)
.onSnapshot((snapshot) => {
if (snapshot.data()) {
customerData = snapshot.data();
startDataListeners();
document.getElementById('loader').style.display = 'none';
document.getElementById('content').style.display = 'block';
} else {
console.warn(
`No Stripe customer found in Firestore for user: ${currentUser.uid}`
);
}
});
} else {
document.getElementById('content').style.display = 'none';
firebaseUI.start('#firebaseui-auth-container', firebaseUiConfig);
}
});
解决方案
您显示的代码中绝对没有任何内容甚至尝试创建文档 - .doc() 只是创建对现有文档的引用。
.onSnapshot 为现有文档的首次读取和后续更改建立侦听器;我不会花时间在 GitHub 上搜索“startDataListeners()”(即使我实际上知道具体的存储库)
如果您希望此代码片段创建一个文档,我建议您花更多时间了解此代码到底在做什么。我强烈怀疑您使用的代码示例期望用户文档已经存在(即您的应用程序创建了它们),并且只是试图将您现有的用户连接到 Stripe 事务
推荐阅读
- python - 修改多边形,使它们不重叠并且面积保持不变
- javascript - React Context API 似乎要重新渲染每个组件
- scala - Akka 如何访问集群中的远程参与者
- php - 在 debian 中安装 php 的问题
- ruby-on-rails - 不允许的参数:ROR
- c# - 找出单击了哪个 Windows 资源管理器窗口来启动我的可执行文件。
- c - C中单个文本字符串中的多个字符数组scanf
- git - git pre-push hook 合并冲突
- google-apps-script - 使用云端硬盘中的图片作为 Google Apps 脚本网络应用程序中的按钮
- android - 如何将 uPort 移动应用程序与我的应用程序集成?