4
새로운 고객이 생성 될 때마다 Firebase 클라우드 기능을 실행하여 Angular 5 프로젝트에 대한 원자 (배치) 업데이트를 작성하려고합니다.Firebase Cloud Functions/Firestore
나는이 오류가 점점 계속하고 문제가 무엇인지 작동하지 않을 수 있습니다
console.error클라우드 기능이 (하는 index.js)Error: Cannot encode type ([object Undefined]) to a Firestore Value at Function.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js:658:11)
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const stripe = require('stripe')(functions.config().stripe.testkey);
// 1. Create Stripe User on sign up
exports.createStripeCustomer = functions.auth.user().onCreate(event => {
// user auth data
const user = event.data;
// register Stripe user
return stripe.customers.create({
email: user.email
})
.then(customer => {
const db = admin.firestore();
const batch = db.batch();
const currentTime = this.timestamp;
const customerDoc = db.collection('customers').doc(customer.id);
const userDoc = db.collection('users').doc(user.uid);
batch.set(customerDoc, {userId: user.uid, timestamp: currentTime });
batch.set(userDoc, {customerId: customer.id, timestamp: currentTime });
return batch.commit();
});
});
나는 또한 당신의 문제가 이것을 약속의 내부에서 부르고 있었다고 말할 것입니다. 나중에 정의되지 않은 문제가 발생하면 let() 호출 전에 let self = this를 정의하고 self.timestamp – sfratini