Derek Jin
Derek Jin

Reputation: 672

Permission denied. Could not perform this operation when using react-firebase-file-uploader

I was trying to upload CSV file to firebase using react-firebase-file-uploader package.

I have set the firebase configuration but when i upload a csv file, I got this 403 error:

error: {
  code: 403
  message: "Permission denied. Could not perform this operation"
}

I have changed the rules in firebase store like this and it worked.

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow write: if true;
      allow read: if true;
    }
  }
}

but when I change it to this it sends me error again:

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

firebase/index.js file

const firebaseConfig = {
  apiKey: "XXXXXX",
  authDomain: "xxx.firebaseapp.com",
  databaseURL: "https://xxx.firebaseio.com",
  projectId: "xxx",
  storageBucket: "xxx.appspot.com",
  messagingSenderId: "XXXXXXX",
  appId: "1:XXX:web:XXX"
};

export default firebaseConfig;

I have set configuration in index.js (root component)file in src folder.

import firebase from 'firebase';
import firebaseConfig from './firebase';


firebase.initializeApp(firebaseConfig);
...

It should work when i change the rule to enable only when there's auth data in request in firebase configuration.

Upvotes: 0

Views: 3298

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317497

This line in your rules:

  allow write: if request.auth != null;

requires that a user be signed in with Firebase Authentication. Other forms of authentication will not work - it has to be through one of the providers (or custom auth) supported by Firebase Authentication.

Firebase security rules don't support any other type of authentication.

Upvotes: 3

Related Questions