首页 > 解决方案 > 如何通过getUserByPhoneNumber使用google-cloud firestore auth获取用户记录?

问题描述

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

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

“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}

标签: node.jsfirebase-authenticationgoogle-cloud-functionses6-promisefirebase-admin

解决方案


我已经使用这种方式来解决该功能。

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)}

推荐阅读