Я использую firebase в качестве серверной части, и я пытаюсь создать пользовательскую функцию, которая записывает в мою базу данных firestore, но я продолжаю работать с ошибками при тестировании моих функций после развертывания. code:
const firebase = require('firebase');
const functions = require('firebase-functions');
const { firebaseConfig } = require('firebase-functions');
const { request } = require('express');
// const { admin } = require('firebase-admin/lib/database');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
let db = admin.firestore();
/*******************************
* *
* INDIVIDUAL *
* *
*******************************/
//Creating a function that will create a Individual user with email & password
// ???: Blair has implemented this in the front end, so likely will not use this function.
exports.createIndividual = functions.https.onRequest((request, Response) =>
{
firebase.auth().createUser(email, password).catch(function(error)
{
// Handle Errors here.
let errorCode = error.code;
let errorMessage = error.message;
// ...
});
})
exports.helloWorld = functions.https.onCall((request, response) => {
response.send("Hello from Firebase!");
});
// Trigger by new user in Firebase: adds their email and UID to the Individuals table for future reference.
// Also Sets the Document name to the user's UID
exports.createIndividualUser = functions.auth.user().onCreate((user) =>
{
let email = user.email
let uid = user.uid
return db.collection("Individuals").doc(uid).set( // admin.database().ref('/Individuals').child.set(
{
Email: email,
UID: uid
}
)
})
Ошибка терминала при тестировании функции:
firebase > createIndividual({email: "test1@test.com", password: "testworks!"})
Sent request to function.
firebase > ! functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
! functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
! functions: FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
at app (C:\Users\pkerv\Documents\back-end\Stakkid\functions\node_modules\@firebase\app\dist\index.node.cjs.js:358:33)
at Object.serviceNamespace [as auth] (C:\Users\pkerv\Documents\back-end\Stakkid\functions\node_modules\@firebase\app\dist\index.node.cjs.js:409:51)
at C:\Users\pkerv\Documents\back-end\Stakkid\functions\index.js:22:15
at C:\Users\pkerv\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:573:20
at C:\Users\pkerv\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:548:19
at Generator.next (<anonymous>)
at C:\Users\pkerv\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:8:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\pkerv\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:4:12)
at runFunction (C:\Users\pkerv\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:545:12)
! Your function was killed because it raised an unhandled error.