Firebase身份验证规则适用于Facebook提供程序,但不适用于电子邮件/密码 [英] Firebase auth rules working for facebook provider but not email/pwd

查看:160
本文介绍了Firebase身份验证规则适用于Facebook提供程序,但不适用于电子邮件/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的数据库上写一些规则,防止用户写入,除非他们使用anonymous之外的提供者进行身份验证。这是我有的规则,但由于某种原因,它的工作时,即时登录与Facebook的,但不是与电子邮件/密码;我得到一个权限被拒绝的错误。 PS电子邮件/ pwd用户是在升级的SDK之前创建的。任何想法,为什么这是行不通的?

 updates:{
.read:auth!= = null,
.write:auth!== null&& auth.provider!=='anonymous',
$ location_id:{
。 indexOn:validFrom,
$ update_id:{
.validate:newData.hasChildren(['displayName','place_id','name','statusValueId','update_id ','user_id','validFrom','votes'])
}
}
},


解决方案

最好的方式来检查为什么这不工作是在firebase控制台中使用模拟器。



你可以在Database> Rules> Simulator(右上角)中找到它
$ b

p>


  1. 在单选按钮中选择写入

  2. Sele ct切换已验证,选择您要测试的提供者并在验证令牌载荷中写入您的用户令牌

  3. 在位置中写入参考路径

  4. 粘贴您要写入的JSON对象的数据(JSON)

  5. 点击运行,firebase会告诉您哪个规则失败


I am trying to write some rules on my DB that prevent the user from writing unless they are authenticated with a provider other than 'anonymous'. This is the rule that I have but for some reason it works when im logged in with facebook but not with email/password; I get a permission denied error. PS the email/pwd user was created before the upgraded SDK. Any thoughts why this is not working?

  "updates": {
    ".read": "auth !== null",
    ".write": "auth !== null && auth.provider !== 'anonymous'",
    "$location_id": {
      ".indexOn": "validFrom",
      "$update_id": {
        ".validate": "newData.hasChildren(['displayName', 'place_id', 'name', 'statusValueId', 'update_id', 'user_id', 'validFrom', 'votes'])"
      }
    }
  },

解决方案

The best way to check why this is not working is using the simulator in the firebase console.

You can find it in Database>Rules>Simulator (top-right corner)

  1. Select Write in the radio button
  2. Select the toggle "Authenticated", select the provider you want to test and write in "Auth token payload" your user's token
  3. Write in "Location" the path to your reference
  4. Paste in "Data (JSON)" the JSON object you want to write
  5. Click run and firebase will tell you which rule fails

这篇关于Firebase身份验证规则适用于Facebook提供程序,但不适用于电子邮件/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆