如何正常处理Firebase权限被拒绝的异常

时间:2022-10-24 13:47:42

Is there any way to avoid permission_denied exception dump on console. I dont want to see that exception on console and want to handle it gracefully. I tried follownig but it does not seems to be working. I also tried .onAuth() but that also does not prevent this happening.

有没有办法在控制台上避免permission_denied异常转储。我不希望在控制台上看到该异常,并希望优雅地处理它。我尝试了follownig,但似乎没有工作。我也试过.onAuth(),但这也不能阻止这种情况发生。

var ref = new Firebase(<My firebase root url>),
 ref.on("value", function(snapshot) {
     console.log("No errors.");
 }, function(err) {
     console.log("Something is wrong. "+err);
 });

Something is wrong. Error: permission_denied: Client doesn't have permission to access the desired data.
SearchCtrl.js:22 User Not Authenticated..Redirecting to Sign In Page...
ionic.bundle.js:19532 Error: permission_denied: Client doesn't have permission to access the desired data.
    at Error (native)
    at J (http://localhost:8100/lib/firebase/firebase.js:120:48)
    at Object.J (http://localhost:8100/lib/firebase/firebase.js:200:378)
    at http://localhost:8100/lib/firebase/firebase.js:185:3
    at vh.h.Hd (http://localhost:8100/lib/firebase/firebase.js:189:104)
    at jh.Hd (http://localhost:8100/lib/firebase/firebase.js:180:364)
    at bh.jh.Da.uh.t [as tg] (http://localhost:8100/lib/firebase/firebase.js:178:281)
    at eh (http://localhost:8100/lib/firebase/firebase.js:172:464)
    at WebSocket.bh.open.va.onmessage (http://localhost:8100/lib/firebase/firebase.js:171:245)(anonymous function) @ ionic.bundle.js:19532c.$$error @ angularfire.min.js:12(anonymous function) @ angularfire.min.js:12(anonymous function) @ angularfire.min.js:12forEach @ ionic.bundle.js:8248g @ angularfire.min.js:12(anonymous function) @ ionic.bundle.js:24148completeOutstandingRequest @ ionic.bundle.js:12830(anonymous function) @ ionic.bundle.js:13210
ionic.bundle.js:19532 destroy called for FirebaseArray: https://fixmycars.firebaseio.com/customers
ionic.bundle.js:19532 TypeError: Cannot read property '$$error' of null
    at angularfire.min.js:12
    at angularfire.min.js:12
    at Object.forEach (ionic.bundle.js:8248)
    at g (angularfire.min.js:12)
    at ionic.bundle.js:24148
    at completeOutstandingRequest (ionic.bundle.js:12830)
    at ionic.bundle.js:13210(anonymous function) @ ionic.bundle.js:19532$get @ ionic.bundle.js:16482(anonymous function) @ ionic.bundle.js:24151completeOutstandingRequest @ ionic.bundle.js:12830(anonymous function) @ ionic.bundle.js:13210

2 个解决方案

#1


Parse the error and/or create a match rule to handle all errors that you would like to handle. Place the handlers inside the else statement in you current structure.

解析错误和/或创建匹配规则以处理您要处理的所有错误。将处理程序放在当前结构中的else语句中。

var ref = new Firebase(<My firebase root url>),
ref.on("value", function(snapshot) {
    if(snapshot.exists()){
        /*Update dom or kick of async method to mount snapshot*/
    }else{
        app.$.errorToast.text = 'Snapshot does not exist';
        app.$.errorToast.show();
    }
    console.log("Did I forget to handle an error");
}, function(err) {
    /*Compare "err" to your rules and handle as needed here*/
    console.log("Something is wrong. "+err);
}); 

Where ever in your code you attempt to complete an action that is not permissive the ".on" function will fire and handle as defined in the single codeblock above.

在您的代码中,您尝试完成一个不允许的操作,“。on”函数将按照上面单个代码块中的定义触发和处理。

To provide good resolution messages to the client such as "The current user is not permitted to access, to gain access contact admin and request user id be added to permission group {myRefMeta.permgroup}". One option I have considered is maintaining another branch that describes the permissions or add a public accessable "descriptor" of the branch in the base node that provides the security details.This knowledge of the user and a discriptor of the tree you are working with you will be able to eliminate this error before it happens.

要向客户端提供良好的解析消息,例如“当前用户不被允许访问,要获取访问权限,请联系管理员并请求将用户ID添加到权限组{myRefMeta.permgroup}”。我考虑过的一个选项是维护另一个描述权限的分支,或者在基本节点中添加一个提供安全性详细信息的分支的公共可访问“描述符”。这个用户知识和你正在使用的树的描述符能够在它发生之前消除这个错误。

In the case that the user logs out and the cache is not cleared your ref.on event will fire again. When this happens you should take care to clear the cache and complete a full reload. This is possible by forcing a refresh of the browser after the cache is cleared.

如果用户注销并且未清除缓存,则ref.on事件将再次触发。发生这种情况时,您应该注意清除缓存并完成完整的重新加载。这可以通过在清除缓存后强制刷新浏览器来实现。

In this code block above the errors are handled in the ref.on and the ref.on will never reach the call to remount the snapshot or update the DOM. By calling a cleanup method in your error handler you can mount an empty snapshot, reset your references and disable features that are not available.

在上面的代码块中,错误在ref.on中处理,ref.on将永远不会到达重新安装快照或更新DOM的调用。通过在错误处理程序中调用清理方法,您可以挂载空快照,重置引用并禁用不可用的功能。

It is optimal for my purposes to wait until permission is needed to request it from a user and by creating a convenience function "referenceCheck" you can use this to kick off authentication and reference creation as needed. This will act as an init method for the "usecase" and the cleanup for that use case will be oh so complimentary to this.

为了我的目的,最好等到需要权限才能从用户请求它并通过创建便利功能“referenceCheck”,您可以根据需要使用它来启动身份验证和参考创建。这将作为“用例”的初始化方法,并且该用例的清理将是如此互补。

#2


Seems you are adding the permission_denied exception dump on console yourself. Do not add the "err" in console log in your error handler function, e.g. console.log("Something is wrong. "+err);

似乎您自己在控制台上添加了permission_denied异常转储。不要在错误处理函数的控制台日志中添加“err”,例如console.log(“有问题。”+错误);

#1


Parse the error and/or create a match rule to handle all errors that you would like to handle. Place the handlers inside the else statement in you current structure.

解析错误和/或创建匹配规则以处理您要处理的所有错误。将处理程序放在当前结构中的else语句中。

var ref = new Firebase(<My firebase root url>),
ref.on("value", function(snapshot) {
    if(snapshot.exists()){
        /*Update dom or kick of async method to mount snapshot*/
    }else{
        app.$.errorToast.text = 'Snapshot does not exist';
        app.$.errorToast.show();
    }
    console.log("Did I forget to handle an error");
}, function(err) {
    /*Compare "err" to your rules and handle as needed here*/
    console.log("Something is wrong. "+err);
}); 

Where ever in your code you attempt to complete an action that is not permissive the ".on" function will fire and handle as defined in the single codeblock above.

在您的代码中,您尝试完成一个不允许的操作,“。on”函数将按照上面单个代码块中的定义触发和处理。

To provide good resolution messages to the client such as "The current user is not permitted to access, to gain access contact admin and request user id be added to permission group {myRefMeta.permgroup}". One option I have considered is maintaining another branch that describes the permissions or add a public accessable "descriptor" of the branch in the base node that provides the security details.This knowledge of the user and a discriptor of the tree you are working with you will be able to eliminate this error before it happens.

要向客户端提供良好的解析消息,例如“当前用户不被允许访问,要获取访问权限,请联系管理员并请求将用户ID添加到权限组{myRefMeta.permgroup}”。我考虑过的一个选项是维护另一个描述权限的分支,或者在基本节点中添加一个提供安全性详细信息的分支的公共可访问“描述符”。这个用户知识和你正在使用的树的描述符能够在它发生之前消除这个错误。

In the case that the user logs out and the cache is not cleared your ref.on event will fire again. When this happens you should take care to clear the cache and complete a full reload. This is possible by forcing a refresh of the browser after the cache is cleared.

如果用户注销并且未清除缓存,则ref.on事件将再次触发。发生这种情况时,您应该注意清除缓存并完成完整的重新加载。这可以通过在清除缓存后强制刷新浏览器来实现。

In this code block above the errors are handled in the ref.on and the ref.on will never reach the call to remount the snapshot or update the DOM. By calling a cleanup method in your error handler you can mount an empty snapshot, reset your references and disable features that are not available.

在上面的代码块中,错误在ref.on中处理,ref.on将永远不会到达重新安装快照或更新DOM的调用。通过在错误处理程序中调用清理方法,您可以挂载空快照,重置引用并禁用不可用的功能。

It is optimal for my purposes to wait until permission is needed to request it from a user and by creating a convenience function "referenceCheck" you can use this to kick off authentication and reference creation as needed. This will act as an init method for the "usecase" and the cleanup for that use case will be oh so complimentary to this.

为了我的目的,最好等到需要权限才能从用户请求它并通过创建便利功能“referenceCheck”,您可以根据需要使用它来启动身份验证和参考创建。这将作为“用例”的初始化方法,并且该用例的清理将是如此互补。

#2


Seems you are adding the permission_denied exception dump on console yourself. Do not add the "err" in console log in your error handler function, e.g. console.log("Something is wrong. "+err);

似乎您自己在控制台上添加了permission_denied异常转储。不要在错误处理函数的控制台日志中添加“err”,例如console.log(“有问题。”+错误);