javascript - Firebase getUserByEmail 不返回用户信息
问题描述
我想通过getUserByEmail函数获取所有用户信息。但它是返回[object Object]。
也许我做错了什么。我只需要通过用户电子邮件获取用户displayName和photoURL 。
我的 Node.js
exports.getUserInfo = functions.https.onCall((data, context) => {
if (context.auth.token.admin !== true) {
return {
message: 'permission denied. Admin role require'
}
}
return admin.auth().getUserByEmail(data.email)
.then(function (userRecord) {
return {
message: 'Successfully fetched user data:' + userRecord.toJSON()
}
})
.catch(function (error) {
return {
message: 'Error fetching user data:' + error
}
});
});
我的 Index.js
const updateForm = document.querySelector('#update-form');
updateForm.addEventListener('submit', (e) => {
e.preventDefault();
const email_st = document.querySelector('#update-email').value;
const getUserInfo = functions.httpsCallable('getUserInfo');
getUserInfo({
email: email_st
}).then(result => {
console.log(result);
});
});
解决方案
您需要对对象进行字符串化才能打印到控制台。
您可以通过以下方式执行此操作:
console.log(JSON.stringify(result));
如果你想用某种格式打印它,你可以使用 -
console.log(JSON.stringify(result, null, 4));
您可以在此处阅读文档以获取更多详细信息。
推荐阅读
- laravel - 在 Laravel 中上传头像注册失败
- react-native - React Native 测量网络带宽使用情况
- ionic-framework - 离子服务在编译 ionic 3 项目时花费了太多时间,例如 4 到 6 分钟
- docker - 关于容器化的 Docker 查询
- cordova - 离子找不到'localforage'的类型定义文件
- laravel - 如何将 sso 与广告与已经使用 oauth 登录的流明应用程序集成?
- sql - MS Access - 不明确的外部连接?
- php - 在 mod_articles_latest 中渲染文章标签
- magento - Magento 1.9 网格中的字符串替换
- haskell - 带有 HXT 的并行 Haskell