FireStore安全规则quest.auth.uid不起作用
2022-04-05 00:00:00
firebase
google-cloud-firestore
vue.js
firebase-authentication
firebase-security
FiRestore安全规则不起作用。
帮帮我。
无法读取用户/用户ID的文档数据。
-安全规则-
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId=**} {
// Missing or insufficient permissions.
allow read, write: if request.auth.uid == userId
// this is work.
//allow read, write: if request.auth != null
}
} )
--------------main.js--------------------
import Vue from 'vue'
import Quasar from 'quasar'
import firebase from 'firebase'
import 'firebase/firestore'
Vue.config.productionTip = false
Vue.use(Quasar)
let app;
firebase.initializeApp({
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
})
firebase.auth().onAuthStateChanged(user=> {
if (user) {
let ref = firebase.firestore().collection('users').doc(user.uid)
ref.get().then(snapshot=>{
// Error !! : Missing or insufficient permissions.
}
}
if(!app){
Quasar.start(() => {
app = new Vue({
el: '#q-app',
render: h => h(require('./App').default)
})
})
}
})
FireBase^4.8.0
VUE^2.5.0
显然,Require.auth.uid似乎不能正常工作。 我哪里错了?
解决方案
我自己解决了
match /users/{user} {
allow read, write: if request.auth.uid == user
match / {docs = **} {
allow read, write: if request.auth.uid == user
}
}
相关文章