1
votes

I'm using Firebase in a React Native app and authentication with a facebook token. It works fine with RealTime Database. But not Firestore. When I call collection.get, set or add I got this error which is not caught by my handler but just dumped in the console.

(node:15795) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: k.setTimeout is not a function

I tried also as a standalone script run as node t_firebase.js.

I installed the packages with

npm install firebase
npm install firestore

I'm using node v6.11.4 and npm 3.10.10, firestore 1.1.6, firebase 4.5.1

Here is the script:

var firebase = require("firebase");
require("firebase/firestore");

var config = {
  apiKey: "...",
  authDomain: "....firebaseapp.com",
  databaseURL: "https://....firebaseio.com",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "..."
};
firebase.initializeApp(config);

testFirebase();

function testFirebase(){
  console.log("testFirebase");
  token="...";
  var credential = firebase.auth.FacebookAuthProvider.credential(token);

  firebase.auth().signInWithCredential(credential)
  .then(function(val){testFirestore();})
  .catch((error)=>{console.log("error:"+error);});
}


function testFirestore(){
  console.log("testFirestore");
  var db = firebase.firestore();
  var collection = db.collection("livros");

  var docref = collection.add({
    autor: "AdaLovelace",
    name: "blabla"
  }).then(function(val){ console.log("OK"); }).catch((error)=>{console.log("error:"+error);});
}
1

1 Answers

1
votes

Although you mention React Native, your error is actually from node.js so I'm not certain which environment you're asking about.