gpt4 book ai didi

javascript - Firebase 云功能/Firestore

转载 作者:搜寻专家 更新时间:2023-10-31 23:23:25 25 4
gpt4 key购买 nike

每当创建新客户时,我都在尝试运行一个 firebase 云函数来为 Angular 5 项目进行原子(批量)更新。

我不断收到此错误,无法确定问题所在:

控制台错误

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)

云函数 (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);

// 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();

});
});

最佳答案

我刚刚发现了错误。我正在定义 currentTimethis.timestamp 但我从未定义过 timestamp

关于javascript - Firebase 云功能/Firestore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47498416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com