Aak*_*kur 20 angularjs firebase angularfire firebase-authentication firebase-realtime-database
我有一个调用addCheckin()方法的页面,它位于控制器内部.在控制器中,我试图创建一个如下引用:
var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");
Run Code Online (Sandbox Code Playgroud)
$scope.whichuser并且$scope.whichmeeting是$routeParams,我从其他途径传递.这是我的签到控制器 -
myApp.controller("CheckinsController",
['$scope','$rootScope','$firebaseArray','$routeParams','$firebaseObject',
function($scope,$rootScope,$firebaseArray,$routeParams,$firebaseObject){
$scope.whichuser = $routeParams.uid;
$scope.whichmeeting = $routeParams.mid;
var ref = firebase.database().ref("users/" + $scope.whichuser + "/meetings/" +$scope.whichmeeting + "/checkins");
$scope.addCheckin = function(){
var checkinInfo = $firebaseArray(ref);
var data={
firstname:$scope.firstname,
lastname:$scope.lastname,
email:$scope.email,
date:firebase.database.ServerValue.TIMESTAMP
}
checkinInfo.$add(data);
}
}]);/*controller*/
Run Code Online (Sandbox Code Playgroud)
我在这里遇到两个错误 -
错误1:
Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings: Client doesn't have permission to access the desired data.
错误2:
Error: permission_denied at /users/Vp2P1MqKm7ckXqV2Uy3OzTnn6bB3/meetings/-KT5tqMYKXsFssmcRLm6/checkins: Client doesn't have permission to access the desired data.
这就是我要实现的目标 -
小智 32
转到应用的Firebase控制台
从侧面菜单中选择数据库 - >从上面的选项卡中选择规则 - >像这样更新规则
{
"rules": {
".read": true,
".write": true
}
}
Run Code Online (Sandbox Code Playgroud)
希望它能解决你的问题.谢谢 :)
mrv*_*klm 10
由于所有提供的答案都包含一个安全问题,每个人都可以在数据库中写入/删除条目,例如,如果使用不当,可能会导致大量成本和/或完全丢失数据。
当然,您需要使用 firebase 身份验证功能来使用这些规则,但默认情况下应阻止匿名的写入访问。以下规则为每个人提供读取访问权限,同时保持安全性。
{
"rules": {
".read": true,
".write": "auth.uid != null"
}
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,Firebase项目以Firestore作为数据库开始。
如果应用程序使用“ Firebase实时数据库”并且未配置其权限,则可能发生此问题。应该明确授予对Firebase实时数据库的读写权限。
为此,请在Firebase控制台中,从“数据库”>“规则”>“设置”旁边的下拉列表中选择“数据库”>“选择实时数据库”,而不是“ Firestore Beta”
{
/* Visit https://firebase.google.com/docs/database/security to learn more about security rules. */
"rules": {
".read": true,
".write": true
}
}
Run Code Online (Sandbox Code Playgroud)
希望对您有所帮助!
这些答案都没有提供设置实时数据库的最安全的方法。
该规则应解决所有情况:
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19327 次 |
| 最近记录: |