[英]Use Firebase uid in firestore (Vue)
I'm using firestore, and I want to use a user's uid
in the query, like this:我正在使用 firestore,我想在查询中使用用户的uid
,如下所示:
methods: {
//...
},
firestore: {
Cards: db.collection("Users").doc(firebase.getCurrentUser().uid).collection("Cards")
},
async beforeMount() {
//...
}
This doesn't work.这是行不通的。 I get this error:我收到此错误:
Uncaught (in promise) FirebaseError: Missing or insufficient permissions.未捕获(承诺)FirebaseError:缺少或权限不足。
I tried just passing the uid as a variable and fetching it in beforeMount()
, but I get this error:我尝试将 uid 作为变量传递并在beforeMount()
中获取它,但出现此错误:
Cannot read properties of undefined (reading 'uid')无法读取未定义的属性(读取“uid”)
What should I do?我应该怎么办?
The issue is with the vuefire binding:问题在于 vuefire 绑定:
https://vuefire.vuejs.org/vuefire/binding-subscriptions.html#programmatic-binding https://vuefire.vuejs.org/vuefire/binding-subscriptions.html#programmatic-binding
If you need to change the bound reference while the application is running, eg to display a different user profile, or different product detail page, Declarative binding isn't enough.如果您需要在应用程序运行时更改绑定引用,例如显示不同的用户配置文件或不同的产品详细信息页面,声明式绑定是不够的。
I had to use Programmatic binding, like this:我不得不使用程序化绑定,如下所示:
const Cards = db.collection('Users')
...
watch: {
uid: {
// call it upon creation too
immediate: true,
handler(uid) {
this.$bind('Cards', Cards.doc(uid).collection("Cards"))
},
},
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.