简体   繁体   English

NativeFirebaseError:[存储/未授权] 用户无权执行所需的操作

[英]NativeFirebaseError: [storage/unauthorized] User is not authorized to perform the desired action

I'm having problems uploading an image to Firebase Storage.我在将图像上传到 Firebase 存储时遇到问题。 I'm using React Native's @react-native-firebase/storage and the installation and connectivity seem to be fine because I'm able to reference images just fine:我正在使用 React Native 的 @react-native-firebase/storage 并且安装和连接似乎很好,因为我能够很好地引用图像:

const ref = firebase.storage().ref('myImage.png');

The problem is definitely permissions based because when I temporarily remove:问题绝对是基于权限的,因为当我临时删除时:

: if request.auth != null

from Firebase console Storage Rules:来自 Firebase 控制台存储规则:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

This worked just fine:这工作得很好:

firebase.storage()
    .ref('images/test.jpg')
    .putFile(myImage[0].path)
    .then((successCb) => {
        console.log('successCb');
        console.log(successCb);
    })
    .catch((failureCb) => {
        console.log('failureCb');
        console.log(failureCb);
    });

So how do I authenticate to use putFile securely?那么我如何进行身份验证才能安全地使用 putFile 呢?

EDIT: I'm using "@react-native-firebase/storage": "^6.2.0"编辑:我正在使用“@react-native-firebase/storage”:“^6.2.0”

Thanks in advance!提前致谢!

That's it Frank!就是这样弗兰克!

I wrongly thought of the app as a user that was already authenticated through the GoogleService-Info.plist file and not that the user of the app needs to be authenticated.我错误地认为该应用程序是已经通过 GoogleService-Info.plist 文件进行身份验证的用户,而不是该应用程序的用户需要进行身份验证。

My steps to fix:我的修复步骤:

  1. install @react-native-firebase/auth安装@react-native-firebase/auth

  2. go into the Authentication section of your firebase console and Enabling the Anonymous Signin method进入 Firebase 控制台的身份验证部分并启用匿名登录方法

  3. call firebase.auth().signInAnonymously() in componentDidMount()在 componentDidMount() 中调用 firebase.auth().signInAnonymously()

    And...finally able submit the putFile to storage successfully!并且...终于能够成功提交 putFile 到存储!

Big thanks @FrankvanPuffelen !!非常感谢@FrankvanPuffelen !!

I'm new in coding, but i face same problem.我是编码新手,但我面临同样的问题。 In my Situation, It did not work with Ananymous SignIn.在我的情况下,它不适用于 Ananymous SignIn。 I had to change the Directory location to make it work.我必须更改目录位置才能使其正常工作。

Original Rule:原规则:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {  => Change here
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Change to:改成:

rules_version = '2';
service firebase.storage {
  match /b/Your_APP_Name.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Edit Firebase storage rules to allow uploads without the need of installing @react-native-firebase/auth .编辑 Firebase 存储规则以允许上传而无需安装@react-native-firebase/auth

  1. Navigate to Firebase console导航到 Firebase 控制台
  2. In Sidebar under Develop open Storage在侧边栏中开发开放存储
  3. Open Rules tab打开规则选项卡
  4. replace below rule替换以下规则
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write
    }
  }
}
  1. And Publish并发布

Done完毕

we can over come this in two ways.我们可以通过两种方式解决这个问题。 either we need to authenticate the user while uploading the files to the database.或者我们需要在将文件上传到数据库时对用户进行身份验证。 or if it is only for the testing purpose i recommend to go to storage in firebase and click on rules and change "allow read, write: if request.auth != null" to "allow read, write: if request.auth == null".或者,如果它仅用于测试目的,我建议转到 firebase 中的存储并单击规则并将“允许读取,写入:if request.auth != null”更改为“允许读取,写入:if request.auth ==空值”。 i recommend to autheticate the user for safe and secure files.我建议对用户进行身份验证以获得安全可靠的文件。

I hope your problem solved.我希望你的问题解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Fire Storage 异常([firebase_storage/unauthorized] 用户无权执行所需的操作。)(我的规则是允许读/写) - Fire Storage Exception ([firebase_storage/unauthorized] User is not authorized to perform the desired action.) (my rule is allow read/write) 用户在调用 cronjob 时无权执行此操作 - User not authorized to perform this action when calling a cronjob 创建对主题的 pubsub 订阅失败,出现错误:用户无权执行此操作 - Creating pubsub subscription to topic failed with error: User not authorized to perform this action AWS Elemental Media Converter - 不允许 Cognito 未经授权的用户执行操作 - AWS Elemental Media Converter - Cognito unauthorized user not allowed to perform action AWS,GitHub 操作:用户无权执行:sts:AssumeRole on resource (CodePipeline) - AWS, GitHub Action: User is not authorized to perform: sts:AssumeRole on resource(CodePipeline) 用户无权执行:dynamodb:GetItem - User is not authorized to perform: dynamodb:GetItem 用户:无权执行:cloudformation:DescribeStacks - User: is not authorized to perform: cloudformation:DescribeStacks 用户无权执行:dynamodb:PutItem on resource - User is not authorized to perform: dynamodb:PutItem on resource AWS 故障注入模拟器返回“未授权执行所需操作”。 - AWS Fault Injection Simulator returning 'Not authorized to perform the required action.' 用户无权执行:connect:* on resource: * with an explicit deny" - User is not authorized to perform: connect:* on resource: * with an explicit deny"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM