2016-11-12 21 views
7

Tôi có cơ sở dữ liệu Firebase được liên kết tối đa hai ứng dụng, một ứng dụng iOS và một ứng dụng web khác được mã hóa trong nút. js là thuật toán cơ bản đặt dữ liệu vào cơ sở dữ liệu. Khi nào tôi đang chạy thuật toán tôi đang phải đối mặt với-Lỗi: Không có Ứng dụng Firebase '[DEFAULT]' được tạo - hãy gọi 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$

Ai đó có thể vui lòng trợ giúp?

Trả lời

3

Tôi gặp sự cố tương tự theo hướng dẫn trực tuyến của Firebase được tìm thấy here.

Tiêu đề phần "Khởi tạo nhiều ứng dụng" là gây hiểu lầm vì ví dụ đầu tiên trong tiêu đề này thực sự chứng tỏ cách khởi tạo một ứng dụng mặc định. Dưới đây là nói ví dụ:

// 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(); 

Nếu bạn đang di chuyển từ SDK 2.x trước, bạn sẽ phải cập nhật theo cách bạn truy cập vào cơ sở dữ liệu như trình bày ở trên, hoặc bạn sẽ nhận được, No Firebase App '[DEFAULT]' lỗi.

Google có tài liệu tốt hơn như sau:

  1. khởi tạo: https://firebase.google.com/docs/database/admin/start

  2. TIẾT KIỆM: https://firebase.google.com/docs/database/admin/save-data

  3. lấy: https://firebase.google.com/docs/database/admin/retrieve-data

2

Đây có thể không phải là câu trả lời hay nhất nhưng, tôi phải khởi chạy ứng dụng bằng quản trị viên và cơ sở dữ liệu như dưới đây. Tôi sử dụng quản trị cho mục đích riêng của nó và firebase là tốt.

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

Có thể bạn đang gọi firebase trước khi ứng dụng được khởi chạy. Tất cả các cuộc gọi đến firebase. phải đến sau.initializeApp();

firebase.initializeApp(config); 
var db = firebase.firestore(); 
Các vấn đề liên quan