Home Firebase database rules for particular user
Reply: 1

Firebase database rules for particular user

Code Guy
1#
Code Guy Published in 2017-12-18 10:26:00Z

I have a db where I need read access to all users and write access when invoked in an apps script running by the user = 'firebaseowner@gmail.com'

My firebase structure is

ABC/AAA1/date 
ABC/AAA2/date 
ABC/AAA3/date 
ABC/AAA4/date 

The rules are:

{
  "rules": {
      ".read": true,
      ".write": false,
    }
}

How do I make the rule to allow write when invoked by the user 'firebaseowner@gmail.com' in the apps script.

I use https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/reference for inserting data

Ben
2#
Ben Reply to 2017-12-18 11:15:56Z

You should check the auth variable.

To define the security rules that allow write access to all the locations by this email address firebaseowner@gmail.com only:

{
  "rules": {
    ".read": true,
    ".write": "auth != null && auth.token.email == 'firebaseowner@gmail.com'"
  }
}

To define the security rules that allow write access to only the location /users by this email address firebaseowner@gmail.com only:

{
  "rules": {
    ".read": true,
    "users": {
      ".write": "auth != null && auth.token.email == 'firebaseowner@gmail.com'"
    }
  }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.314234 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO