My app is working just fine but when I use the Firebase emulators, I have a problem with the Storage rules not being obeyed.
I have downloaded the storage.rules
file and it is in the same directory as the firebase-json
file. The Emulator suite launches just fine and I can see that the Storage emulator is working.
However, when I try to upload an image (as I do in the live app) I get an error.
Error while uploading file: Error Domain=FIRStorageErrorDomain Code=-13021 "User does not have permission to access gs://my-stuff-7796d.appspot.com/Profiles/0ye7psTQA4xR6DfjZRXjjtCWKyPw.jpg." UserInfo={object=Profiles/0ye7psTQA4xR6DfjZRXjjtCWKyPw.jpg, ResponseBody={"error":{"code":403,"message":"Permission denied. No WRITE permission."}}, bucket=my-stuff-7796d.appspot.com, data={length = 74, bytes = 0x7b226572 726f7222 3a7b2263 6f646522 ... 73696f6e 2e227d7d }, data_content_type=application/json; charset=utf-8, NSLocalizedDescription=User does not have permission to access gs://my-stuff-7796d.appspot.com/Profiles/0ye7psTQA4xR6DfjZRXjjtCWKyPw.jpg., ResponseErrorDomain=com.google.HTTPStatus, ResponseErrorCode=403}
The storage.rules are:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
Again, running against the live Firebase works just fine and the rules are obeyed. Here is my firebase.json file
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
},
"emulators": {
"auth": {
"port": 9099
},
"firestore": {
"port": 8080
},
"storage": {
"port": 9199
},
"ui": {
"enabled": true
}
}
}
When I launch my app, this is the code I initialize after call FirebaseApp.configure
Auth.auth().useEmulator(withHost:"localhost", port:9099)
Storage.storage().useEmulator(withHost:"localhost", port:9199)
let settings = Firestore.firestore().settings
settings.host = "localhost:8080"
settings.isPersistenceEnabled = false
settings.isSSLEnabled = false
Firestore.firestore().settings = settings
What am I missing, or is this a bug?