【问题标题】:JS Google Cloud Function Error: Reference.update failed: First argument contains undefined in propertyJS Google Cloud 函数错误:Reference.update 失败:第一个参数在属性中包含未定义
【发布时间】:2019-06-11 15:22:52
【问题描述】:

这是 JS 中的 Google Cloud 函数,我收到以下错误,该函数成功创建了 Stripe 客户,但无法写回数据库。

我猜它与snap.uid 有关,对吗?以及如何获取为触发该功能而创建的User节点的uid

错误:Reference.update 失败:第一个参数包含未定义的 属性

exports.createStripeCustomerFromUser = functions.database.ref('/users/{userId}').onCreate((snap, context) => {

  const userSnap = snap.val(); 

  const first = userSnap.firstName;
  const last = userSnap.lastName;
  const email = userSnap.email;
  const description = first + ' ' + last;

  return stripe.customers.create({
    email: email,
    description: description,
    name: description,
  }).then((customer) => {
    var updatedUserData = {};
    updatedUserData[`/stripe_ids/${customer.id}`] = snap.uid;
    updatedUserData[`/stripe_customers/${snap.uid}/customer_id`] = customer.id;
    return admin.database().ref().update(updatedUserData);

  });

});

【问题讨论】:

    标签: javascript firebase-realtime-database google-cloud-functions


    【解决方案1】:

    在你的情况下,使用

    context.params.userId
    

    userId 来自

    ref('/users/{userId}')
    

    【讨论】:

      猜你喜欢
      • 2021-02-12
      • 2021-03-03
      • 1970-01-01
      • 2018-08-18
      • 2018-04-26
      • 1970-01-01
      • 2015-11-06
      • 2016-04-14
      • 2018-08-08
      相关资源
      最近更新 更多