用户信息"/>
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
回答如下:您需要对对象进行字符串化处理才能打印到控制台。
您可以按照以下步骤进行:
console.log(JSON.stringify(result));
如果要以某种格式打印它,则可以使用-
console.log(JSON.stringify(result, null, 4));
您可以阅读文档here了解更多详细信息。
更多推荐
Firebase getUserByEmail不返回用户信息
发布评论