【问题标题】:How to get the verified phone number in firebase cloud functions?如何在 Firebase 云功能中获取经过验证的电话号码?
【发布时间】:2020-02-14 12:28:00
【问题描述】:

当用户验证其电话号码时,我有此功能可以添加自定义声明

exports.phoneCustomClaim = functions.auth.user().onCreate((user) => {
    const sellerNumber = user.phone; // here i am not getting the phone number
    const uid = user.uid;
    const customClaims = {
      number: sellerNumber,
    };

    console.log(`Uid: ${uid}, number: ${sellerNumber}`);

    console.log(`before Seller number: ${sellerNumber}`);
    return admin.auth().setCustomUserClaims(uid, customClaims).then(() => {
        console.log(`claim added!`);
    })
    .catch(error => {
        console.log(error);
    })
});

日志

Uid: 1mlxF1T8xcWbByAzQ7rfKjdshj, number: undefined

请问如何获得那个电话号码?

【问题讨论】:

    标签: firebase firebase-authentication google-cloud-functions


    【解决方案1】:

    我怀疑在实际验证电话号码之前创建了用户帐户(但未通过身份验证)。这类似于电子邮件验证流程的工作原理。

    如果是这种情况,您将不得不解决该问题。由于当前在更新用户配置文件时不会触发 Cloud Functions,因此您可以做的最好的事情是在用户验证其电话号码后从您的代码中调用可调用的 Cloud Functions。

    【讨论】:

    • functions.auth.user().onCreate() 在用户验证他们的电话号码时触发,因为您看到我得到的是 UID 但不是验证号码。我以为我获取 user.uid 的方式有没有办法获取 user.phone 或任何东西?
    • 你确定它是在验证时触发的,而不是更早的?将验证过程延迟几分钟,检查功能日志,然后确定。
    • 我明白你说的,但触发器是如何在验证之前触发的?因为在验证之后会在 firebase auth 中添加一个新用户,如果它在验证之前触发,那么每次当用户尝试验证电话号码时,都会在验证用户之前在 firebase auth 中创建一个新用户。
    • 因此,如果您致电signInWithPhoneNumber 并在确认代码之前等待,用户(尚未)显示在 Firebase 控制台中?
    • 这个我没试过。让我试试
    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 2018-03-23
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 2020-11-08
    • 2018-05-17
    相关资源
    最近更新 更多