Firebase身份验证规则适用于Facebook提供程序,但不适用于电子邮件/密码 [英] Firebase auth rules working for facebook provider but not email/pwd
问题描述
我试图在我的数据库上写一些规则,防止用户写入,除非他们使用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>
- 在单选按钮中选择写入
- Sele ct切换已验证,选择您要测试的提供者并在验证令牌载荷中写入您的用户令牌
- 在位置中写入参考路径
- 粘贴您要写入的JSON对象的数据(JSON)
- 点击运行,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)
- Select Write in the radio button
- Select the toggle "Authenticated", select the provider you want to test and write in "Auth token payload" your user's token
- Write in "Location" the path to your reference
- Paste in "Data (JSON)" the JSON object you want to write
- Click run and firebase will tell you which rule fails
这篇关于Firebase身份验证规则适用于Facebook提供程序,但不适用于电子邮件/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!