Я хочу анонимно подключиться к Firestore и получить некоторые данные из коллекции. Это отлично работает под javascript, но не работает («FirebaseError: Отсутствуют или недостаточные разрешения») под node.js. Приветствуются любые указатели.
Это код, который работает без сучка и задоринки под javascript (я пропустил включение «скрипта»), и он возвращает данные, как ожидалось:
var config = {
apiKey: "xxx",
authDomain: "xxx.firebaseio.com",
projectId: "xxx",
storageBucket: "xxx.appspot.com",
};
firebase.initializeApp(config);
firebase.auth().signInAnonymously().catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(error.message);
});
foo();
async function foo() {
var db=firebase.firestore();
var query = await db.collection("collection").limit(5).get();
query.forEach(function(doc) {
console.log(doc.data());
});
}
Это код, который не работает под node.js. Config / authdata точно такой же, как в примере js выше. (Он использует библиотеку firebase (client). Насколько я понимаю, библиотека firebase-admin не позволяет анонимный вход.)
const firebase=require('firebase');
var config = {
apiKey: "xxx",
authDomain: "xxx.firebaseio.com",
projectId: "xxx",
storageBucket: "xxx.appspot.com",
};
firebase.initializeApp(config);
firebase.auth().signInAnonymously().catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(error.message);
});
let db = firebase.firestore();
db.collection('collection').get()
.then((snapshot) => {
snapshot.forEach((doc) => {
console.log(doc.id, '=>', doc.data());
});
})
.catch((err) => {
console.log('Error getting documents', err);
});
Следующая ошибка возникает, когда db.collection ('collection ') .get () . (ранее анонимное подписание проходит)
Error getting documents { FirebaseError: Missing or insufficient permissions.
at new FirestoreError (/root/node_modules/@firebase/firestore/dist/index.node.cjs.js:1201:28)
at JsonProtoSerializer.fromRpcStatus (/root/node_modules/@firebase/firestore/dist/index.node.cjs.js:19708:16)
at JsonProtoSerializer.fromWatchChange (/root/node_modules/@firebase/firestore/dist/index.node.cjs.js:19955:44)
at PersistentListenStream.onMessage (/root/node_modules/@firebase/firestore/dist/index.node.cjs.js:16828:43)
at /root/node_modules/@firebase/firestore/dist/index.node.cjs.js:16757:30
at /root/node_modules/@firebase/firestore/dist/index.node.cjs.js:16797:28
at /root/node_modules/@firebase/firestore/dist/index.node.cjs.js:17844:20
at process._tickCallback (internal/process/next_tick.js:68:7)
code: 'permission-denied',
name: 'FirebaseError',
toString: [Function] }
Еще раз спасибо за любые указатели!