【发布时间】:2021-01-26 00:19:10
【问题描述】:
我更新了我的 Firebase 实时数据库访问规则,并注意到一些客户端现在尝试访问他们无权访问的路径。这没关系 - 但我的问题是我的代码在无法读取受限节点后停止。
我在控制台中看到以下错误,然后停止加载后续数据:
permission_denied at /notes/no-access-node
我首先从/access_notes/uid 收集访问节点,然后继续从/notes/noteId 读取所有数据。
我从下面的数据库中收集notes的代码:
//*** SUBSCRIPTION */
database.ref(`access_notes/${uid}`).on('value', (myNotAccessSnaps) => {
let subscrPromises = []
let collectedNots = {}
// Collect all categories we have access to
myNotAccessSnaps.forEach((accessSnap) => {
const noteId = accessSnap.key
subscrPromises.push(
database.ref(`notes/${noteId}`)
.once('value', (notSnap)=>{
const notData = notSnap.val()
const note = { id: notSnap.key, ...notData}
collectedNotes[note.id] = note
},
(error) => {
console.warn('Note does not exist or no access', error)
})
)
})
Promise.all(subscrPromises)
.then(() => {
const notesArray = Object.values(collectedNotes)
...
})
.catch((error) => { console.error(error); return Promise.resolve(true) })
我不希望客户端在permission_denied 上停止!
有没有办法在不引发错误的情况下查看用户是否可以访问节点/notes/no_access_note?
亲切的问候 /K
【问题讨论】:
标签: javascript firebase-realtime-database es6-promise firebase-security