How to set Firebase database rules for group messaging app
I have set Firebase database rules for a group messaging app. But now even when an authenticated user tries to send a message it doesn't get displayed.
I am working on a group messaging app. The code can be found at the following link. When creating the app I was using default rules for the Firebase database. But now I am trying set rules so that all the uid available in the members node can see or send messages to that particular group. Below are the latest set of rules that I have created. Below is my detailed database structure after a plan is created. Please note that I am making use of Firebase Phone Authentication. For this reason I am creating a users node which keeps track of uid against every registered number. When a user selects members to be added to the group I check those numbers against their respective uid's and then add those uid's in the member's node.
{
"rules": {
"plan":{
"$planID":{
"messages":{
".read":"data.parent().child('members').child(auth.uid).exists()",
".write":"data.parent().child('members').child(auth.uid).exists()"
}
}
}
}
}
I expected authenticated users who have been added to the members node to be able to read and send messages but instead even the registered users themselves cannot create a new group or read the messages after the above rules have been published.
firebase firebase-realtime-database firebase-security-rules
add a comment |
I have set Firebase database rules for a group messaging app. But now even when an authenticated user tries to send a message it doesn't get displayed.
I am working on a group messaging app. The code can be found at the following link. When creating the app I was using default rules for the Firebase database. But now I am trying set rules so that all the uid available in the members node can see or send messages to that particular group. Below are the latest set of rules that I have created. Below is my detailed database structure after a plan is created. Please note that I am making use of Firebase Phone Authentication. For this reason I am creating a users node which keeps track of uid against every registered number. When a user selects members to be added to the group I check those numbers against their respective uid's and then add those uid's in the member's node.
{
"rules": {
"plan":{
"$planID":{
"messages":{
".read":"data.parent().child('members').child(auth.uid).exists()",
".write":"data.parent().child('members').child(auth.uid).exists()"
}
}
}
}
}
I expected authenticated users who have been added to the members node to be able to read and send messages but instead even the registered users themselves cannot create a new group or read the messages after the above rules have been published.
firebase firebase-realtime-database firebase-security-rules
Please include the code you are using to test this and your database structure as text.
– André Kool
Jan 1 at 23:01
@AndréKool I have added a link to the github repository of the project
– RCR
Jan 2 at 6:23
add a comment |
I have set Firebase database rules for a group messaging app. But now even when an authenticated user tries to send a message it doesn't get displayed.
I am working on a group messaging app. The code can be found at the following link. When creating the app I was using default rules for the Firebase database. But now I am trying set rules so that all the uid available in the members node can see or send messages to that particular group. Below are the latest set of rules that I have created. Below is my detailed database structure after a plan is created. Please note that I am making use of Firebase Phone Authentication. For this reason I am creating a users node which keeps track of uid against every registered number. When a user selects members to be added to the group I check those numbers against their respective uid's and then add those uid's in the member's node.
{
"rules": {
"plan":{
"$planID":{
"messages":{
".read":"data.parent().child('members').child(auth.uid).exists()",
".write":"data.parent().child('members').child(auth.uid).exists()"
}
}
}
}
}
I expected authenticated users who have been added to the members node to be able to read and send messages but instead even the registered users themselves cannot create a new group or read the messages after the above rules have been published.
firebase firebase-realtime-database firebase-security-rules
I have set Firebase database rules for a group messaging app. But now even when an authenticated user tries to send a message it doesn't get displayed.
I am working on a group messaging app. The code can be found at the following link. When creating the app I was using default rules for the Firebase database. But now I am trying set rules so that all the uid available in the members node can see or send messages to that particular group. Below are the latest set of rules that I have created. Below is my detailed database structure after a plan is created. Please note that I am making use of Firebase Phone Authentication. For this reason I am creating a users node which keeps track of uid against every registered number. When a user selects members to be added to the group I check those numbers against their respective uid's and then add those uid's in the member's node.
{
"rules": {
"plan":{
"$planID":{
"messages":{
".read":"data.parent().child('members').child(auth.uid).exists()",
".write":"data.parent().child('members').child(auth.uid).exists()"
}
}
}
}
}
I expected authenticated users who have been added to the members node to be able to read and send messages but instead even the registered users themselves cannot create a new group or read the messages after the above rules have been published.
firebase firebase-realtime-database firebase-security-rules
firebase firebase-realtime-database firebase-security-rules
edited Jan 2 at 6:19
RCR
asked Jan 1 at 22:02
RCRRCR
14
14
Please include the code you are using to test this and your database structure as text.
– André Kool
Jan 1 at 23:01
@AndréKool I have added a link to the github repository of the project
– RCR
Jan 2 at 6:23
add a comment |
Please include the code you are using to test this and your database structure as text.
– André Kool
Jan 1 at 23:01
@AndréKool I have added a link to the github repository of the project
– RCR
Jan 2 at 6:23
Please include the code you are using to test this and your database structure as text.
– André Kool
Jan 1 at 23:01
Please include the code you are using to test this and your database structure as text.
– André Kool
Jan 1 at 23:01
@AndréKool I have added a link to the github repository of the project
– RCR
Jan 2 at 6:23
@AndréKool I have added a link to the github repository of the project
– RCR
Jan 2 at 6:23
add a comment |
1 Answer
1
active
oldest
votes
When defining every sub-node as Integers, starting from zero (as you did in
members
), Firebase automatically interprets the whole node as it if was an Array of Objects, and in such case you cannot treat them as if they were sub-nodes at all (by callingchild(auth.uid)
).
Quote from the link:
In particular, if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase will render it as an array. This latter part is important to keep in mind.
Since this is the case in your Data Structure, all of
members
' sub-nodes are no longer considered nodes. They are array items, and therefore are notchildren
ofmembers
.
Even if it weren't the case, and they were all sub-nodes - you seem to call
child(auth.uid)
as ifauth.uid
was an Integer: Your "sub-nodes" are all Integers, whileauth.uid
is defined String.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999283%2fhow-to-set-firebase-database-rules-for-group-messaging-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When defining every sub-node as Integers, starting from zero (as you did in
members
), Firebase automatically interprets the whole node as it if was an Array of Objects, and in such case you cannot treat them as if they were sub-nodes at all (by callingchild(auth.uid)
).
Quote from the link:
In particular, if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase will render it as an array. This latter part is important to keep in mind.
Since this is the case in your Data Structure, all of
members
' sub-nodes are no longer considered nodes. They are array items, and therefore are notchildren
ofmembers
.
Even if it weren't the case, and they were all sub-nodes - you seem to call
child(auth.uid)
as ifauth.uid
was an Integer: Your "sub-nodes" are all Integers, whileauth.uid
is defined String.
add a comment |
When defining every sub-node as Integers, starting from zero (as you did in
members
), Firebase automatically interprets the whole node as it if was an Array of Objects, and in such case you cannot treat them as if they were sub-nodes at all (by callingchild(auth.uid)
).
Quote from the link:
In particular, if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase will render it as an array. This latter part is important to keep in mind.
Since this is the case in your Data Structure, all of
members
' sub-nodes are no longer considered nodes. They are array items, and therefore are notchildren
ofmembers
.
Even if it weren't the case, and they were all sub-nodes - you seem to call
child(auth.uid)
as ifauth.uid
was an Integer: Your "sub-nodes" are all Integers, whileauth.uid
is defined String.
add a comment |
When defining every sub-node as Integers, starting from zero (as you did in
members
), Firebase automatically interprets the whole node as it if was an Array of Objects, and in such case you cannot treat them as if they were sub-nodes at all (by callingchild(auth.uid)
).
Quote from the link:
In particular, if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase will render it as an array. This latter part is important to keep in mind.
Since this is the case in your Data Structure, all of
members
' sub-nodes are no longer considered nodes. They are array items, and therefore are notchildren
ofmembers
.
Even if it weren't the case, and they were all sub-nodes - you seem to call
child(auth.uid)
as ifauth.uid
was an Integer: Your "sub-nodes" are all Integers, whileauth.uid
is defined String.
When defining every sub-node as Integers, starting from zero (as you did in
members
), Firebase automatically interprets the whole node as it if was an Array of Objects, and in such case you cannot treat them as if they were sub-nodes at all (by callingchild(auth.uid)
).
Quote from the link:
In particular, if all of the keys are integers, and more than half of the keys between 0 and the maximum key in the object have non-empty values, then Firebase will render it as an array. This latter part is important to keep in mind.
Since this is the case in your Data Structure, all of
members
' sub-nodes are no longer considered nodes. They are array items, and therefore are notchildren
ofmembers
.
Even if it weren't the case, and they were all sub-nodes - you seem to call
child(auth.uid)
as ifauth.uid
was an Integer: Your "sub-nodes" are all Integers, whileauth.uid
is defined String.
edited Jan 2 at 4:12
answered Jan 2 at 3:49


BarackosBarackos
540315
540315
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999283%2fhow-to-set-firebase-database-rules-for-group-messaging-app%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please include the code you are using to test this and your database structure as text.
– André Kool
Jan 1 at 23:01
@AndréKool I have added a link to the github repository of the project
– RCR
Jan 2 at 6:23