Kohei Okazaki
Kohei Okazaki

Reputation: 53

About firebase storage rule match

I want to grant a user something like that.

match /images/{userId}/{allPaths=**}

But my firebaseStorage path is like that.

match /images/user/userId_user.jpg

So I don't know how to match this paths.

And.. If you know use uid don't use match {userId}<- like that.

kind regard.

Upvotes: 2

Views: 576

Answers (1)

Mike McDonald
Mike McDonald

Reputation: 15953

I recommend storing your files in a different format to make this easier:

match /users/{userId}/images/{imageId} {
  allow write: if userId == request.auth.uid;
}

which can match /users/userId/images/user.jpeg

But if you're already in this format, you're lucky we provide string and regular expression matching:

match /images/user/{userImageName} {
  // If you know it'll be just a straight string match, go for it
  allow read if: userImageName == request.auth.uid + '_user.jpeg';
  // Otherwise match using a regular expression
  allow write if: userImageName.matches(request.auth.uid + '_user.jpeg');
}

Upvotes: 4

Related Questions