javascript - 调用 firebase 函数返回 null
问题描述
我正在调用 Functions 函数来获取用户信息,但它返回 null。请告诉我解决方案。
工作区/函数/src/index.ts
exports.getUser = functions.https.onCall((data, context) => {
admin.database().ref(`user/${data.userId}`)
.on('value', (snapshot) => {
if (snapshot) return snapshot.val();
});
});
工作区/src/app/sample.component.ts
firebase.functions().httpsCallable('getUser')({
userId: profile.userId
}).then(data => {
console.log(data);
}).catch(error => {
alert(error);
});
解决方案
您没有在 https 可调用中返回任何内容,请添加返回:
exports.getUser = functions.https.onCall((data, context) => {
return admin.database().ref(`user/${data.userId}`)
.on('value', (snapshot) => {
if (snapshot) return snapshot.val();
});
});
推荐阅读
- c# - 如何在 dot net core 3.0/3.1 的剃须刀页面中添加区域?
- haskell - 重写函数haskell
- azure-devops - 构建管道在“初始化作业”步骤失败
- docker - Docker info 显示容器,但 docker container ls 不显示
- python - 如果某些键具有所需的值,如何遍历字典列表并打印字典
- c# - 打印时的 C# 字符变成数字
- eval - 如何在 Boomla 中启用 eval()
- javascript - 如何在响应式显示的一行上添加一个类?
- c# - 无会话的 XML 加密/解密
- c++ - 可能的 MacOS Catalina 提升安装名称错误?