我使用Stripe付款.为此,我在Firestore中有以下数据模型:
Users/{userId}/payments/{document}
Run Code Online (Sandbox Code Playgroud)
每个{document}都是一个看起来像这样的对象:
{
amount: 55
token: {...}
charge: {...}
}
Run Code Online (Sandbox Code Playgroud)
用户必须能够编写该token字段(这是传递给服务器的内容),但我不希望用户能够编写该charge字段.
目前我的规则允许任何用户读取和写入此文档:
match /payments/{documents} {
allow read, write: if request.auth.uid == userId;
}
Run Code Online (Sandbox Code Playgroud)
什么Firestore规则将实现我所期望的安全性?
stripe-payments firebase firebase-security google-cloud-firestore
如何从命令行以管理员身份验证以转储/查询我的firestore中的数据?例如,我有一个users集合,每个文档看起来像:
{
edit_count: 15
}
Run Code Online (Sandbox Code Playgroud)
我只是想在我的终端中将所有这些文件打印为json.
我使用过firebase-tools,但看起来它只支持查询RTDB?
我想在firebase函数中使用phantomjs的屏幕捕获功能来返回URL的PDF屏幕截图.寻找有人这样做的例子.
我有一个React应用程序,它使用react-router和一个看起来像的Router:
<Router>
<div>
<Route exact path="/" component={Homepage} />
<Route path="/map/:uid" component={Userpage} />
<Footer />
</div>
</Router>
Run Code Online (Sandbox Code Playgroud)
该应用使用Firebase托管进行托管。
如果我打开我的网站并单击以使路由器将我带到/ map / uid,则可以正常加载。但是,如果我关闭浏览器,然后尝试显式导航到<domain>/map/<known uid>,则会从Firebase获得“找不到页面”页面。这是我第一次使用react-router。
更新#1
我已更新firebase.json为:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我不再收到“找不到页面”页面;但是,我的react应用程序的内容永远不会加载,并且我在控制台中注意到一个错误:
Uncaught SyntaxError: Unexpected token <
Run Code Online (Sandbox Code Playgroud)
更新#2
我现在明白为什么我得到了错误。在Chrome开发者工具中查看Sources标签,只有当我直接导航到时,我的static /文件夹才使用一个奇怪的名称(static/css而不是static)/map/{known uid}。当我导航到主页时,所有加载都正常。
这解释了错误。我仍然不确定如何解决。
我正在尝试测试标题为 uid 的文档是否存在。我已确认该文档存在于用户集合中的 Firestore 中,但 doc.exists 始终返回 false。请注意,我的文档 uid 仅包含集合(无字段)。
firebase.auth().onAuthStateChanged((user) => {
if (user) {
// User is signed in.
var uid = user.uid
db.collection("users").doc(uid)
.get()
.then((doc) => {
console.log(doc)
if (doc.exists) {
console.log('returning user')
} else {
console.log('new user')
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
} else {
// User is signed out.
// ...
}
Run Code Online (Sandbox Code Playgroud)