0
votes

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 = '[email protected]'

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 '[email protected]' in the apps script.

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

1
Keep empty rules ( remove rules) - Nitin Dhomse
what is the default rule? - Code Guy

1 Answers

3
votes

You should check the auth variable.

To define the security rules that allow write access to all the locations by this email address [email protected] only:

{
  "rules": {
    ".read": true,
    ".write": "auth != null && auth.token.email == '[email protected]'"
  }
}

To define the security rules that allow write access to only the location /users by this email address [email protected] only:

{
  "rules": {
    ".read": true,
    "users": {
      ".write": "auth != null && auth.token.email == '[email protected]'"
    }
  }
}