gpt4 book ai didi

javascript - 对新创建的文档使用 Get() 时 Firestore 规则失败

转载 作者:行者123 更新时间:2023-12-03 17:36:28 25 4
gpt4 key购买 nike

在 Firestore 规则中对新创建的文档使用 get() 会导致返回值为 false。如果您等待几秒钟并遇到在同一个新文档上调用 get() 的安全规则,则 get() 将返回预期值。我是否遗漏了规则和/或代码中的某些内容,或者这是 Firestore 的错误?

service cloud.firestore {
match /databases/{database}/documents {

match /budgets/{budgetId} {

allow read: if resource.data.userId == request.auth.uid;
allow create: if request.auth.uid == request.resource.data.userId;

match /accounts/{accountId} {
allow read, create, update: if userOwnsBudget(); // <--- failing for newly created budget documents
}

function userOwnsBudget() {
return get(/databases/$(database)/documents/budgets/$(budgetId)).data.userId == request.auth.uid;
}
}
}
}



const data: Budget = {
userId: userId,
budgetName: budgetName,
currencyType: currencyType
};

try {
const newBudget = await this.afs.collection<Budget>('budgets').add(data);

const accountsCollection: AngularFirestoreCollection<BudgetAccount> = this.afs.collection<BudgetAccount>('budgets/' + newBudget.id + '/accounts');

//Insufficient permission, but occasionally succeeds
accountsCollection.valueChanges().subscribe(accounts => {
console.log(accounts);
});

setTimeout(() => {
accountsCollection.valueChanges().subscribe(accounts => {
console.log(accounts)
});
}, someArbitaryTime) // Typically waiting 5 seconds is enough, but occasionally that will still fail

} catch(error) {
console.error(error);
}

最佳答案

编辑:此错误已解决。

不幸的是,这是目前已知的问题。我们正在修复,一旦解决将在此处更新。谢谢和抱歉!

关于javascript - 对新创建的文档使用 Get() 时 Firestore 规则失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47360760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com