3

I'm using the following rules:

service firebase.storage {
  match /b/xxxxxxx.appspot.com/o {
match /proUsers/{userId}/{allPaths=**} {
      allow read, write: if request.auth.uid == userId && request.resource.size < 2 * 1024 * 1024 && request.resource.contentType.matches('image/.*'); 
    }
  }
}

This is how I'm creating the ref for saving:

storageRef.child(`proUsers/${userId}/${prizeData.title}_${prizeData.createdAtTimeStamp}`).put(file, metadata)

Attempting to delete it I'm creating this Ref:

  const prizeImageRef = storageRef.child(`proUsers/${userId}/${prizeData.title}_${prizeData.createdAtTimeStamp}`)
  return prizeImageRef.delete()

I keep getting the 403 error:

code : "storage/unauthorized"

Firebase Storage: User does not have permission to access

Are my rules for deletion not correct?

jasan
  • 11,475
  • 22
  • 57
  • 97

1 Answers1

1

Yeah, I think the main issue here is that request.resource.contentType.matches('image/.*') is going to be null because you won't get the contentType on DELETE.

Mike McDonald
  • 15,609
  • 2
  • 46
  • 49