Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: User is not authorized to perform the desired action. #560

Closed
shekharskamble opened this issue Oct 29, 2017 · 16 comments
Closed

Error: User is not authorized to perform the desired action. #560

shekharskamble opened this issue Oct 29, 2017 · 16 comments
Labels
resolution: user Issue with users code or an issue that should be directed to Stack Overflow or the Discord server.

Comments

@shekharskamble
Copy link

Issue

I am trying to upload image files in the storage using following code

import RNfirebase from 'react-native-firebase';

RNfirebase.storage().ref('tablen_ame').putFile(uploadUri).then(uploadedFile => {
//setting some state
})
.catch(err => {
console.log(err);
});

getting the error as "User is not authorized to perform the desired action."

Following is the storage rules in Firebase

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

I am also initializing FIrebase upon start of an app

import RNfirebase from 'react-native-firebase';
RNfirebase.initializeApp({...

AM I missing something or doing anything wrong?

Environment

  1. Application Target Platform: Android
  1. Development Operating System: Windows 10
  1. Build Tools: VS code
  1. React Native version: 0.49.3
  1. RNFirebase Version: 3.0.5
  1. Firebase Module: storage
@Salakar Salakar added the resolution: user Issue with users code or an issue that should be directed to Stack Overflow or the Discord server. label Nov 2, 2017
@perrosnk
Copy link

perrosnk commented Mar 6, 2018

@shekharskamble how did you solve this?

@pilot4u
Copy link

pilot4u commented Apr 11, 2018

👍 1

@ha-hamed
Copy link

@shekharskamble how did you manage to solve and close this issue? I am having the same issue and I bet others too ! A feedback would be real appreciative

@shekharskamble
Copy link
Author

Extremely sorry for replying late, I don't exactly remember how did I solve this one but can you please try putting file in a folder like this

.ref(foldername/${fileName}).putFile(uploadUri)

you can set any file name you want.

@perrosnk
Copy link

@shekharskamble This still doesn't work for me. Can this issue be re-opened?

@shekharskamble
Copy link
Author

reopened...

@gcyagyu
Copy link

gcyagyu commented May 2, 2018

@perrosnk
I encountered the same error, and I solve error now!
How is the rule of your Fire base storage?
I change the rule below, so I can solve the error.
I want you to try it!

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

@Ehesp
Copy link
Member

Ehesp commented May 2, 2018

@gcyagyu That opens the security rules to anyone.

@shekharskamble
Copy link
Author

@gcyagyu - agreed to @Ehesp its bad...

@perrosnk
Copy link

perrosnk commented May 2, 2018

@gcyagyu this is not safe

I want to enable each user to upload ONLY his profile photo. My rules look like this:

service firebase.storage {
  match /b/{bucket}/o {
    match /users/{userId}/{filename} {
      allow read;
      allow write: if request.auth.uid == userId
      						 && filename == "profilePicture.jpeg"
      						 && request.resource.size < 300 * 1024
      						 && request.resource.contentType.matches('image/.*')
      						 && request.resource.contentType == resource.contentType
    }
  }
}

If I deactivate the last 2 lines:

&& request.resource.contentType.matches('image/.*')
&& request.resource.contentType == resource.contentType

it works. But I need this two lines for security reasons. Is anyone else facing this kind of problem?

@chrisbianca
Copy link
Contributor

@perrosnk looks like you're running into a side effect of #739 with your security rules.

We plan on addressing this as part of the 4.1.x release stream - we don't yet have a timescale I'm afraid, but in the meantime you may need to lower the security rules.

I'm going to close this issue, as we now understand the reasoning. Track #739 for updates.

@Salakar
Copy link
Contributor

Salakar commented Jul 7, 2018

@perrosnk have implemented a fix for mime/content types as part of the upcoming v4.3.0 release, mime types are automatically detected correctly now when uploading and can also be overridden using custom metadata. Should fix your rules issue.

Thanks for reporting!

@minuhariharan
Copy link

We are facing the same issue and keep seeing this error : [storage/unauthorized] User is not authorized to perform the desired action. The user is authenticated and these are our storage rules: rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}. From the usage stats i can see that this rule is accepted half the times and denied half the times, but we always make a check if the user is authenticated and then upload. How did you resolve this issue?

@mikehardy
Copy link
Collaborator

I don't think that will have anything to do with react-native-firebase, i.e., it will not be a problem with this module. I think firebase storage has a rules simulator that can be used to try out different scenarios real time, maybe that would point out the problem in combo with the documentation.

All I can suggest if you want to come at it from react-native-firebase's direction is to put console logs with arguments and results of each API call logged out before it goes down to the firebase-android-sdk and firebase-ios-sdk layers in Java and Objective-C to see exactly what is going in and coming out when things aren't behaving the way you want. That's usually how I find my project-specific coding errors when working with firebase. Hope this helps

@perrosnk
Copy link

@minuhariharan Could it be related to this? #4690

@ryyvv
Copy link

ryyvv commented Apr 24, 2024

i try the simulation of my rules and perfectly fine, it matches my database structure but when i store image with my react native app to my different storage bucket it shows an error , is says error always ::: " ERROR [Error: [storage/unauthorized] User is not authorized to perform the desired action.]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolution: user Issue with users code or an issue that should be directed to Stack Overflow or the Discord server.
Projects
None yet
Development

No branches or pull requests