0

I've created an android app and used firebase as means to email sign up and authentication. After signing up, users can store inventory items in the database. So my question is how would i setup firebase authentication rules so that specific user can access only the data they entered. Right now, everyone can read/write in the database. I'm not worried about the write part, because of email authentication. Thanks in advance!

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

My data base is set in this way:Database

1 Answer 1

1

You can make use of built-in variables to reach that.

The Firebase Database Rules include built-in variables and functions that allow you to refer to other paths, server-side timestamps, authentication information, and more. Here's an example of a rule that grants write access for authenticated users to /users//, where is the ID of the user obtained through Firebase Authentication.

{
  "rules": {
    "users": {
      "$uid": {
        ".write": "$uid === auth.uid"
      }
    }
  }
}

Link

https://firebase.google.com/docs/database/security/

Sign up to request clarification or add additional context in comments.

3 Comments

I get the basic gist of it, but how would i get access to the emails that are in database already. I'm sorry, i'm a beginner at android and firebase stuff.
/users/04VsBqpZmseOdJCKj4r8BP4MVem2/email maybe? It depends on the way to have structured your data.
Thanks for the pic. Where are expecting to take the email from? I can't see any field related to emails on this picture. If you want to take it from Predefined Variables, the you might get it from the variable auth.token. e.g auth.token.email_verified on your rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.