{
"rules": {
".read": true,
".write": true,
".delete": true
}
}
these rules show me error Error saving rules - Line 5: Expected '{'.
Please help
Firebase Realtime Database rules don't support a ".delete" clause, and that's the reason you get this error message. Correct rules are:
{
"rules": {
".read": true,
".write": true
}
}
These rules will also allow deleting of the data, as part of the .write rule.
If you want to later disallow deletes or other types of updates, have a look at the documentation on new data vs existing data.
Related
I've created a list of banned users in my realtime Database and I want to make them impossible to log-in, I know I can use the database rules, but I don't know how, can someone help me?
This is my database structure:
/banned-users:
/UserId1:True
/UserId2:True
Those are my database rules:
{
"rules": {
".read": true,
".write": true
}
}
You need to reference data in other paths as follows:
{
"rules": {
"thepath": {
".read": "root.child('banned-users').child(auth.uid).val() !== true"
".write": "root.child('banned-users').child(auth.uid).val() !== true"
}
}
}
Note that actually you don't "make them impossible to log-in", because this is not possible, but you prevent them writing to/reading from your database.
I m using firebase Database .Planning to have quite a large data collection , I'm trying to use indexes . Making some tests, i don t know if rules i implement are correct let alone improve the queries .Is there a way to have a feedback on those indexations (correct or not, improve or not)
right now i have one class as described in the picture and i have the created the following rule
{
"rules": {
".read": true,
".write": true,
"users": {
"$user_id": {
".indexOn": ["user_id", "username"]
}
},
}
Since i get no feedback from firebase, i don t know if this is correct and improves anything .
Firebase's server-side rules are meaningless without seeing the code that exercises them.
But at a first glance it seems you're defining your indexes too low in the tree: indexes need to be defined at the location where you run the query. So if you want to run a query on /users, you need to define the indexes on /users:
{
"rules": {
".read": true,
".write": true,
"users": {
".indexOn": ["user_id", "username"]
}
}
}
I have an iOS app where I have to implement a simple chat between two users. I am registering the users to Firebase during app registration. All work good. But when I have to start a chat thread I am searching for a user using search indexes but I am getting following error:
Using an unspecified index. Consider adding ".indexOn": "phone" at /use_frameworks_beta_2/searchIndex to your security rules for better performance
Using an unspecified index. Consider adding ".indexOn": "email" at /use_frameworks_beta_2/searchIndex to your security rules for better performance
Using an unspecified index. Consider adding ".indexOn": "name" at /use_frameworks_beta_2/searchIndex to your security rules for better performance
The Rules in Firebase console is as follows
{
"rules": {
".read": true,
".write": true,
"searchIndex": {
".indexOn": ["email","phone","name"]
}
}
}
Please help me fixing this error.
The .indexOn specifier must be placed in the rules at the location containing the indexed keys. Update your rules to place .indexOn at the correct location in the tree:
{
"rules": {
".write": true,
".read": true,
"use_frameworks_beta_2": {
"searchIndex ": {
".indexOn": ["email","phone","name"]
}
}
}
}
I am trying to retrieve some data from Firebase but it won't retrieve anything unless I am signed in first. I've already tried editing my database's rules and setting the values to true.
Here are the Rules
{
"rules": {
".read": true,
".write": true
}
}
In your Firebase console, you can click on Database --> Rules (Tab)
In there you can specify whether or not you need to be authenticated in order to retrieve your data.
"rules": {
".read": "auth == null",
".write": "auth == null"
}
I would only leave it this way for testing. It's pretty easy to setup the simple anonymous Auth through Firebase :) Best of luck!
In case if you don't want any security you can use the below rules
"rules": {
".read": "true",
".write": "true"
}
I decided to use Firebase in an old objectiv C iOS app.
I installed what I needed following the instructions given here:
Add Firebase to your iOS app right after login into Firebase.
Then I followed the instructions given here:
https://firebase.google.com/docs/database/
in order to work with a database.
At this point it basically works, I can write some data.
Nevertheless I have this issue about the Rules settings.
I followed the information given here:
https://firebase.google.com/docs/database/security/quickstart
But if I set my rules like this:
{
"rules": {
".read": true,
".write": true
}
}
it works as expected. On the other hand, if I set them like this:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
which is the default and should allow me to write data from my app, it does not work.
What is the problem?
If you don't want the user to login, you could automatically authenticate the user anonymously.
Authenticate with Firebase Anonymously on iOS
Then you could use:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
After reading your comment in reply to cartant,it is clear that you want to allow your app users to access your database for reading and writing , without need of signing in.
I would also like to do this without requesting the user to login. Is this possible?
YES
It is possible to allow your users to access your DB without any signing process.
Actually
{
"rules": {
".read": true,
".write": true
}
}
this rule says that you are providing read and write permission to your user without signing in.
On the other hand
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
in this rule you are mentioning that your authentication ("auth != null")has to be performed before granting the read , write permissions to your user.
So to accomplish your goal just use the default rule i.e rule without authentication.