4
新しい顧客が作成されるたびに、Firebase Cloud機能を実行して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();
});
});
私はまたあなたの問題がこれを約束の中で呼んでいたかもしれないと言っています。未定義の問題が後で発生した場合は、then()呼び出しの前にlet self = thisを定義し、self.timestamp – sfratini