【问题标题】:How to get the user Record using the google-cloud firestore auth by getUserByPhoneNumber?如何通过getUserByPhoneNumber使用google-cloud firestore auth获取用户记录?
【发布时间】:2020-02-26 10:44:46
【问题描述】:

我必须通过电话号码使用身份验证从用户那里提取数据。 我有一组用户的电话号码。

我已经编写了一个解决方案,它提供了所需的输出,但它不会终止。我该如何解决这个问题?

“phoneNumberArray”是用户电话号码的数组。它主要与 HTTP 后台触发功能有关。我已经解决了这个问题,但这是一个 firebase 问题,所以请看这个

const user = async () => {
    const getAuth = async phoneNumber => {
        return auth.getUserByPhoneNumber(phoneNumber).catch(() => {
            return {
                phoneNumber,
                uid: null,
                email: '',
                displayName: '',
                emailVerified: false,
                disabled: false,
            };
        });
    };

    const userRecord = await Promise.all(
        phoneNumberArray.map(phoneNumber => {
            return getAuth(phoneNumber);
        }),
    );
    //when i console.log(userRecord) it's print the output
    const x = {
        'userRecord Length': userRecord.length
    }
    console.log(x)
    return;
}
   module.exports = {user}

【问题讨论】:

  • but it doesn't terminate - 什么不会终止?您发布的功能是否会到达 console.log?如果是这样,那么函数就完成了——也许你叫错了
  • 顺便说一句,phoneNumberArray.map(phoneNumber => { return getAuth(phoneNumber); }) 更简单地写成phoneNumberArray.map(getAuth)
  • @JaromandaX 当我运行节点文件名时,它不会关闭并打印输出,如果我删除此代码,它将终止,我也使用了你的建议,但仍然遇到同样的问题
  • @JaromandaX 你能告诉我我说错了什么吗?
  • 因此,您的代码会输出 console.log(x) 的结果,但不会终止,并且,如果您删除此代码,则代码会终止 - 这是我从您的评论中了解到的。那么,您如何调用您在问题中提出的函数?

标签: node.js firebase-authentication google-cloud-functions es6-promise firebase-admin


【解决方案1】:

我已经用这种方式解决了函数。

in the main file i have to return 
return x,admin;
and the calling file works like this
const {user} = require('./filename');
user().then(e => {
console.log(e.x)
e.admin.apps[0].delete();
})catch(error){
console.log(error)}

【讨论】:

    猜你喜欢
    • 2020-01-11
    • 2019-09-30
    • 1970-01-01
    • 2019-02-08
    • 2018-04-01
    • 2019-05-12
    • 1970-01-01
    • 2018-05-20
    • 2020-09-05
    相关资源
    最近更新 更多