我正在尝试使用我的应用程序中的 Firebase 云功能将电子邮件和用户姓名发布到带有随机生成的 ID 的云 Firestore 集合中。一切正常,但我想从一个函数获得对我的应用程序的响应,但我真的无法做到这一点。这是我的应用程序中调用云函数的代码:
onPress ({commit, dispatch}, payload) {
var addUserInformation = firebase.functions().httpsCallable('addUserInformation');
addUserInformation(payload)
.then(function(result) {
console.log(result)
}).catch(function(error) {
var code = error.code;
var message = error.message;
var details = error.details;
console.log(code);
console.log(message);
console.log(details);
});
},
Run Code Online (Sandbox Code Playgroud)
这是云函数的代码:
const functions = require('firebase-functions')
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.addUserInformation = functions.https.onCall((data) => {
admin.firestore().collection('Backend').where('email', '==', data[1]).get()
.then(function(querySnapshot) {
if (querySnapshot.size > 0) {
console.log('Email already exists') …Run Code Online (Sandbox Code Playgroud)