Firebase Security Rules for Storage
You need a corresponding File Path structure:
For example when you upload the file store them like this:
(root…) /user/uidxxx/myfile.jpg
Where "uidxxx " is the Unique User ID defined in your authentication database.
Then on the console/storage / Rules tab you can write the rule:
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/<your-firebase-storage-bucket>/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
{userId}
is a wildcard that will be replaced by the corresponding "uidxxx"