Kashif
Kashif

Reputation: 4632

Firebase database security rules to allow anonymous as well as web access

Below rules on my firebase database allow anonymous logins through my iOS app.

{
    "rules": {
        ".read": "auth != null",
        ".write": "auth != null",
        "locations": {
      ".indexOn": "g"
    }
    }
}

That works well but now I need to add access for my JS web app which works through the apiKey. How do I add that rule here?

Upvotes: 0

Views: 1238

Answers (1)

kkesley
kkesley

Reputation: 3406

Could you login anonymously on the JS web app? I copied this code from https://firebase.google.com/docs/auth/web/anonymous-auth

firebase.auth().signInAnonymously().catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // ...
});

if you don't want to login (which I don't think you want to), just replace

auth != null

with

true

Upvotes: 3

Related Questions