I'm trying to create a mixed authentication for my firebase storage. The public section would have general access to common items like photos, and private one (after authentication). However, even after setting my rules, my Android studio project is denying access to even the public items. My AndroidManifest has access to internet permission. My firebase rules are as follows:
rules_version = '2';
// Craft rules based on data in your Firestore database
// allow write: if firestore.get(
// /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
service firebase.storage {
match /b/{bucket}/o {
match /purchasers/{email}/images {
allow read,write :if request.auth != null && request.auth.token.email == email;
}
match /public/images {
allow read,write :if request.auth == null;
}
}
}
The code that I'm using to access Firebase storage is this:
fun getPublicImages(): MutableList<String> {
val imageList: MutableList<String> = mutableListOf()
val fbStorage = Firebase.storage
val imageRef = fbStorage.reference.child("/public/images")
Log.d("PurchaserViewModel", imageRef.path)
imageRef.listAll()
.addOnSuccessListener { (items) ->
for (item in items) {
imageList.add(item.path)
Log.d("PurchaserViewModel", item.path)
}
}
.addOnFailureListener( ) {
Log.d(TAG, it.message.toString())
}
return imageList
}
The purpose for this function and public access to /public/images folder is because I'm using it for a user registration page in my app where the user can select a temporary icon until user logs in. Once a user logs in, he will be able to access the /purchasers/{email}/images folder after authentication. The part of the documentation that I'm trying to follow is: https://firebase.google.com/docs/storage/security/rules-conditions#public. The funny part is that access is granted in the rules playground for unauthenticated public access, but it is denied when my app tries to access it.