Firebase存储规则导致用户无权访问

问题描述 投票:1回答:1

我试图从firebase存储加载用户配置文件图像,但我一直在运行Cause(1 of 1):

com.google.firebase.storage.StorageException类:用户无权访问此对象。

用户身份验证:

mFirebaseAuth.signInWithEmailAndPassword(mEmailView.getText().toString(), mPasswordView.getText().toString())

这是我的firebase规则:

service firebase.storage {
  match /b/brainbeats-e9839.appspot.com/o {
    match /user/{userId}/{allPaths=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}

像这样滑行加载:

    StorageReference storageReference = FirebaseStorage.getInstance().getReference();
    StorageReference imageStorage = storageReference.child("images/" + user.getArtistProfileImage());

    GlideApp.with(this)
            .load(imageStorage)
            .into(mArtistCoverImage);
android firebase firebase-storage firebase-security
1个回答
0
投票

那么你的规则授予以下访问权限:

/user/{userId}/{allPaths=**}

所以用户下的任何路径然后是用户ID位置,然后是任何东西

但是你正在访问

/images/xyzpath

现在,由于这不在/ user / variable userid /下,因此会出现异常。

为什么不在用户节点下移动图像,如:

/user/{userId}/images/yourpath

如果auth规则匹配,这应该停止给出错误。如果它是未经授权的用户访问另一个用户ID,它仍然会崩溃,所以最好将所有内容放在try catch块中

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.