2
votes

I have problem with firestore db call with api key in my nuxt app.

If I work with default security rules its fine. But when i use google's recommended rules :

allow read, write: if request.auth.uid != null; 

I got this error.

Error getting documents:  FirebaseError: "Missing or insufficient permissions."

 FirestoreError index.cjs.js:352 fromRpcStatus index.cjs.js:5844 fromWatchChange index.cjs.js:6341 onMessage index.cjs.js:14912 startStream index.cjs.js:14841 getCloseGuardedDispatcher index.cjs.js:14881 newTail index.cjs.js:7636 

My firestore configuration file, information and API key are corrects on my file config. I'm working with API key in project => global setting => apikey :

import firebase from 'firebase'

var config = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: ""
};

if (!firebase.apps.length) {
    firebase.initializeApp(config)
}
export const db = firebase.firestore();
export default firebase
1

1 Answers

1
votes

This rule:

allow read, write: if request.auth.uid != null; 

is saying that all access to the matched documents can only come from an authenticated user. Authentication must be done by Firebase Authentication integrated into the app. The rule will reject any access where the user is not currently signed in, or if Firebase Authentication is not in use.