somethingelse
somethingelse

Reputation: 61

Firebase database authentication by email

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

Upvotes: 0

Views: 452

Answers (1)

Victor Hugo Montes
Victor Hugo Montes

Reputation: 1322

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/

Upvotes: 1

Related Questions