如何确保用户只能在Firebase中查看和访问他们自己的数据? [英] How to make sure a user can only see and access their own data in firebase?
本文介绍了如何确保用户只能在Firebase中查看和访问他们自己的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- b'LI>如何写信给我的火力地堡数据在我的Android的Java代码?
谢谢!
火力地堡规则
{
的规则:{
的.read :真,
的.WRITE:真
}
}
Java代码的
myFirebaseRef.child( 消息)的setValue( 这是消息)。
解决方案
由于乔伊Roosing,我能够找出其余的。我需要根据用户的uid对数据进行分组。
首先,修改Firstbase规则,如Joey所说:
{
的规则:{
的用户:{
$ UID:{
.write:$ uid === auth.uid,
.read:$ uid === auth.uid
}
}
$ b 然后,在我的Java代码中:
Firebase rootRef =新的Firebase(https://user-account.firebaseio.com/);
//假设用户已经登录。
Firebase userRef = rootRef.child(users /+ rootRef.getAuth()。getUid());
userRef.child(message1)。setValue(Hello World);
最后,我的数据会是这个样子:
I am new to firebase. In my Android app, I want each user to only access the data he created. I was reading https://www.firebase.com/docs/security/guide/securing-data.html, but didn't make much sense out of it. Assuming I am already logged in with an email and password,
- How can should I write the Firebase Rules?
- How do write to my Firebase data in my Android Java code?
Thanks!
Firebase Rules
{
"rules": {
".read": true,
".write": true
}
}
Java Code
myFirebaseRef.child("message").setValue("This is the message");
解决方案 Thanks to Joey Roosing, I was able to figure out the rest of it. I need to group the data based on the uid of the user.
First, modify the Firstbase rules as Joey mentioned:
{
"rules": {
"users": {
"$uid": {
".write": "$uid === auth.uid",
".read": "$uid === auth.uid"
}
}
}
}
Then, in my Java Code:
Firebase rootRef = new Firebase("https://user-account.firebaseio.com/");
// Assuming the user is already logged in.
Firebase userRef = rootRef.child("users/" + rootRef.getAuth().getUid());
userRef.child("message1").setValue("Hello World");
In the end, my data would look something like this:
这篇关于如何确保用户只能在Firebase中查看和访问他们自己的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文