I am trying to run the firebase cloud function to create an atomic (batch) update for an Angular 5 project when a new client is created.
I keep getting this error and can't decide what the problem is:
console.errorError: cannot encode type ([object Undefined]) into Firestore value in Function.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/src/document.js: 658: 11)
Cloud Functions (index.js)const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const stripe = require('stripe')(functions.config().stripe.testkey);
exports.createStripeCustomer = functions.auth.user().onCreate(event => {
const user = event.data;
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();
});
});
source
share