我只想将firbase安装为数据库,但不断收到此错误:
ERROR Error: permission_denied at /courses: Client doesn't have permission to access the desired data.
at errorForServerCode (index.cjs.js:647)
at onComplete (index.cjs.js:9114)
at Object.onComplete (index.cjs.js:12681)
at index.cjs.js:11797
at PersistentConnection.push../node_modules/@firebase/database/dist/index.cjs.js.PersistentConnection.onDataMessage_ (index.cjs.js:12052)
at Connection.push../node_modules/@firebase/database/dist/index.cjs.js.Connection.onDataMessage_ (index.cjs.js:11337)
at Connection.push../node_modules/@firebase/database/dist/index.cjs.js.Connection.onPrimaryMessageReceived_ (index.cjs.js:11331)
at WebSocketConnection.onMessage (index.cjs.js:11232)
at WebSocketConnection.push../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.appendFrame_ (index.cjs.js:10837)
at WebSocketConnection.push../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.handleIncomingFrame (index.cjs.js:10887)
Run Code Online (Sandbox Code Playgroud)
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { environment } from '../environments/environment';
imports: [
BrowserModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFireDatabaseModule, …Run Code Online (Sandbox Code Playgroud) javascript firebase firebase-realtime-database angular6 firebase-security-rules
我正在构建一个非常简单的基于JavaScript的Firebase应用程序,该应用程序在每次加载网页时会将键的值增加1。我不希望任何身份验证冲突,因此想使用一个开放数据库或一个仅限于匿名身份验证的数据库。因此,例如:
$(document).ready(function() {
// after config and initialize...
var fb = firebase.database();
var fbCount = fb.ref("count");
fbCount.transaction(function(current) {
return current + 1;
});
});
Run Code Online (Sandbox Code Playgroud)
根据我的理解,无论哪种情况,都无法阻止任何可以访问页面的人复制我的代码(包括我的初始化配置)并在自己的服务器上使用它进行调整-不仅增加值(fbCount以上),但可以通过他们喜欢的任何其他方式更改代码(例如,让他们将值增加100、1000,或将其完全更改为其他值)。
我的进一步理解是应对这种潜力的最佳方法是通过安全规则。所以我想弄清楚的是,是否有一种方法可以通过安全规则将任何写入限制为仅将当前值增加1?
如果没有,还有其他方法我应该调查吗?
firebase firebase-security firebase-realtime-database firebase-security-rules
我可以使用array_containsFirebase安全规则中的等价物吗?
我有一Event堂课(对应Event于events馆藏文件)。每个文档都有一个subscribers列表/数组,其中包含应该能够查询此事件的所有用户的UID:
{
.
"subscribers" : ["uidA", "uidB", "uidC"],
.
}
Run Code Online (Sandbox Code Playgroud)
更明确地说,用户应该能够运行查询:
db().collection("events").whereArrayContains("subscribers", "uidC");
Run Code Online (Sandbox Code Playgroud)
如何编写此安全规则?
我试过了:
match/events/{eventId} {
allow list: if request.auth.uid in resource.data.subscribers;
}
Run Code Online (Sandbox Code Playgroud)
模拟器告诉我访问将被拒绝。
使用这样的功能还会报告访问被拒绝:
function isSubscriber() {
return resource.data.subscribers.includes(request.auth.uid);
}
match/events/{eventId} {
allow list: if isSubscriber();
}
Run Code Online (Sandbox Code Playgroud) 我知道这是一个常见问题,但是我没有找到以前的问题。
我创建了一个新的firebase项目,并且正在尝试使用它。我创建了public,因此每个人都可以与之合作:
权限
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试发布一个对象时,出现了一个错误:
错误:未捕获(承诺):错误:PERMISSION_DENIED:权限被拒绝错误:PERMISSION_DENIED:权限被拒绝
如果数据库当前是公共的,我怎么没有权限?我该怎么解决?
我的代码很简单:
宾语
export class Coordenate {
$key: string;
latitude: number;
longitude: number;
}
Run Code Online (Sandbox Code Playgroud)
打字稿组件
onAddMarker(event) {
this.databaseService.postCoordenate(event.coords.lat, event.coords.lng);
//this.latitude = event.coords.lat;
//this.longitude = event.coords.lng;
}
Run Code Online (Sandbox Code Playgroud)
服务
listToStore: AngularFireList<any>;
//Insert a new bet
postCoordenate(latitude, longitude) {
this.listToStore = this.db.list("coordenates");
//Get the value of the photo URL in subscribe
this.listToStore.push({
latitude: latitude,
longitude: longitude
});
}
Run Code Online (Sandbox Code Playgroud)
该firebaseConfig是添加到我environment在我的角度项目
firebase firebase-realtime-database angular firebase-security-rules
我有一个Firebase项目,该项目使用Firestore。我经常在Firebase控制台上手动修改安全规则和索引,但是我的开发机上也有本地副本(Firestore.rules和Firestore.indexes.json),当我这样做时,它们会变得不同步。
我想知道什么是同步它们的最佳实践。到目前为止,我将这些更改手动应用于本地副本,但这显然是一个容易出错的过程。
我不想通过部署过时的规则来意外覆盖这些设置。
我将不胜感激任何建议。
我有一个使用Firebase的聊天应用程序,它继续使用
x处的setValue失败:DatabaseError:权限被拒绝
每次输入消息时都会出错.
我已将数据库设置为公开:
service cloud.firestore {
match /databases/{database}/documents {
match /{allPaths=**} {
allow read, write: if request.auth.uid != null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的聊天参考内容吗?
private void displayChat() {
ListView listOfMessage = findViewById(R.id.list_of_message);
Query query = FirebaseDatabase.getInstance().getReference();
FirebaseListOptions<Chat> options = new FirebaseListOptions.Builder<Chat>()
.setLayout(R.layout.list_item)
.setQuery(query, Chat.class)
.build();
adapter = new FirebaseListAdapter<Chat>(options) {
@Override
protected void populateView(View v, Chat model, int position) {
//Get reference to the views of list_item.xml
TextView messageText, messageUser, messageTime;
messageText = v.findViewById(R.id.message_text);
messageUser = v.findViewById(R.id.message_user);
messageTime = v.findViewById(R.id.message_time); …Run Code Online (Sandbox Code Playgroud) android firebase firebase-realtime-database firebase-security-rules