my app is using this code in flutter to upload images:
final StorageReference imageRef = FirebaseStorage.instance.ref().child('postimages');
final StorageUploadTask uploadTask = imageRef.child('/' + currentUser.id + '/post_$postid.jpg').putFile(_image);
var upurl = await (await uploadTask.onComplete).ref.getDownloadURL();
url = upurl.toString();
debugPrint('url:$url');
which is working fine if i grant full rewrite access by these unrecommended rules:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
but if i try to implement any security for example with this rule:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
i end up getting the following exception: [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: PlatformException(Error -13021, FIRStorageErrorDomain, User does not have permission to access gs://picturegramm.appspot.com/postimages/118190432651181005229/post_b050df01-7b58-4016-8d3c-28c7f3ace630.jpg., null)
The app is using firebase authentication with google as sign-in provider. Reading the docs it looks like the auth info is always sent automatically. The signing seems to work perfectly, since i am getting the current user with the userid. So why do the requests fail?
final user = FirebaseAuth.instance.currentUser;
user
will be null if the user isn't logged in. – Gabe