![](/img/trans.png)
[英]Can't get onCreate function to trigger using TypeScript on Cloud Firestore
[英]How to update or set property of firestore document after .onCreate cloud function trigger
我目前正在尝试通过使用Cloud Functions for Firebase将Stripe与Firebase的Cloud Firestore数据库集成。 onCreate
触发器发生正确,但我也希望它将其更新或设置一个名为“ customer_id”的特定字段到我的用户集合中的正确文档中。 我认为关于函数的编写方式有些不足,因为我不是最有经验的javascript。
我也尝试过
return admin.firestore().ref(`Users/${user.uid}/customer_id`).set(customer.id);
'use strict';
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
//const logging = require('@google-cloud/logging')();
const stripe = require('stripe')(functions.config().stripe.token);
const currency = functions.config().stripe.currency || 'USD';
// When a user is created, register them with Stripe
exports.createStripeCustomer = functions.auth.user().onCreate((user) => {
return stripe.customers.create({
email: user.email,
}).then((customer) => {
return admin.firestore().collection("Users").doc(user.uid).update({"customer_id": customer.id})
});
});
使用Stripe创建客户没有问题,但是Firestore数据库上的“ customter_id”字段未更新。
如评论中所述,在错误日志的打印屏幕上,您已部署的代码与您在问题中引用的代码不对应。
您问题中的代码看起来正确。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.