I'm trying to set a rule, in firebase for storage, where only the authenticated user can write his avatar image called avatar
This is firebase docs example:
// Grants a user access to a node matching their user ID
service firebase.storage {
match /b/{bucket}/o {
// Files look like: "user/<UID>/path/to/file.txt"
match /user/{userId}/{allPaths=**} {
allow read, write: if request.auth.uid == userId;
}
}
}
and these are my rules defined in storage.rules file:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
match /images/{allPaths=**} {
allow write: if request.resource.size < 5 * 1024 * 1024
&& request.resource.contentType.matches("image/.*")
&& request.resource.contentType == resource.contentType
}
match /images/user-{userId}/avatar.* {
allow read;
allow write: if request.auth.uid == userId;
}
}
}
When I deploy the error thrown is
[E] 13:25 - Unexpected 'userId'
I can't find anything else in the docs telling me how to defined this userId. The docs specify it and what am I doing wrong?
/images/user-{userId}
, but instead/images/{userId}
– Doug Stevenson/images/user/{userId}/avatar
not/images/user-{userId}/avatar
, aren't you ? – Ali Faris