Error: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp()

后端 未结 9 688
慢半拍i
慢半拍i 2020-12-01 15:55

I have a firebase database linked up to two apps, one being an iOS app and another being a web app coded in node.js which is a basic algorithm that sets data to the database

9条回答
  •  旧时难觅i
    2020-12-01 16:03

    This may not be best answer but, I had to initialize app with admin and firebase like below. I use admin for it's own purposes and firebase as well.

    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);
                });
        }
    

提交回复
热议问题