2016-11-12 3 views
7

firebaseデータベースは2つのアプリケーションにリンクされています.1つはiOSアプリ、もう1つはノードにコード化されたWebアプリケーションです。 jsはデータベースにデータを設定する基本的なアルゴリズムです。私はError:Firebase App '[DEFAULT]'が作成されていません - Firebase App.initializeApp()を呼び出してください

Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp(). at Error (native) at R (/Users/dd/Desktop/Code/NODE/node_modules/firebase/app-node.js:22:335) at a (/Users/dd/Desktop/Code/NODE/node_modules/firebase/app-node.js:20:68) at Object.c [as database] (/Users/dd/Desktop/Code/NODE/node_modules/firebase/app-node.js:21:447) at Object. (/Users/dd/Desktop/Code/NODE/Bot.js:24:25) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3 dd-mac:NODE dd$

with-直面していたアルゴリズムを実行しています今までにすると誰かが助けてくださいもらえますか?

答えて

3

Firebaseのオンラインガイドで同様の問題が発生しました。hereです。

この見出しの下の最初の例は、単一のデフォルトアプリを実際に初期化する方法を実際に示しているため、「複数のアプリを初期化する」という見出しのセクションは誤解を招くことがあります。ここでは例として言われています:

// Initialize the default app 
var defaultApp = admin.initializeApp(defaultAppConfig); 

console.log(defaultApp.name); // "[DEFAULT]" 

// Retrieve services via the defaultApp variable... 
var defaultAuth = defaultApp.auth(); 
var defaultDatabase = defaultApp.database(); 

// ... or use the equivalent shorthand notation 
defaultAuth = admin.auth(); 
defaultDatabase = admin.database(); 

以前の2.xのSDKから移行する場合は、上記のように、データベースにアクセスする方法を更新する必要があります、またはあなたは、No Firebase App '[DEFAULT]'エラーになります。

  1. INITIALIZE:https://firebase.google.com/docs/database/admin/start

  2. SAVE:https://firebase.google.com/docs/database/admin/save-data

  3. がRETRIEVE: https://firebase.google.com/docs/database/admin/retrieve-data

2

Googleは、以下でより良いドキュメントを持っていますこれは最善の答えではないかもしれませんが、私は以下のようにadminとfirebaseでアプリケーションを初期化しなければなりませんでした。私はそれ自身の目的とfirebaseのための管理者を使用します。

const firebase = require("firebase"); 
const admin = require("firebase-admin"); 

admin.initializeApp(functions.config().firebase); 
firebase.initializeApp(functions.config().firebase); 
// Get the Auth service for the default app 
var authService = firebase.auth(); 

function createUserWithEmailAndPassword(request, response) { 
     const email = request.query.email; 
     const password = request.query.password; 
     if (!email) { 
      response.send("query.email is required."); 
      return; 
     } 
     if (!password) { 
      response.send("query.password is required."); 
      return; 
     } 
     return authService.createUserWithEmailAndPassword(email, password) 
      .then(success => { 
       let responseJson = JSON.stringify(success); 
       console.log("createUserWithEmailAndPassword.responseJson", responseJson); 
       response.send(responseJson); 
      }) 
      .catch(error => { 
       let errorJson = JSON.stringify(error); 
       console.log("createUserWithEmailAndPassword.errorJson", errorJson); 
       response.send(errorJson); 
      }); 
    } 
0

アプリが初期化される前におそらくfirebaseが呼び出されています。 firebase.へのすべての呼び出しは、後を来なければならない.initializeApp();

firebase.initializeApp(config); 
var db = firebase.firestore(); 
関連する問題