我一直在尝试使用提供给每个用户的 id 来检索存储在我的 firebase 项目中的不同用户的数据,但是不知何故,当我将数据传递给 thunder 客户端时,它显示无效用户或用户不存在。
这是我写的代码
module.exports.getUserDetails = async (req, res) => {
const uid = req.query.id; // retrieve user ID from query parameters
if (!uid || uid.length>128){
res.status(400).json({error:"invalid user"})
}
try {
const userRecord = await admin.auth().getUser(uid); // get user record from Firebase Auth
console.log(userRecord)
const userRef = db.collection("users").doc(uid);
const userDoc = await userRef.get(); // get user data from Firestore
if (!userDoc.exists) {
return res.status(404).json({ error: "User not found" });
}
const userData = userDoc.data();
return res.status(200).json(userData); // return user details as JSON
} catch (error) {
console.error(error);
console.log(error)
return res.status(500).json({ error: "Server error" });
}
};
我将 url 传递为 localhost:4000/d?id=my_id
我将 index.js 文件中的函数称为 app.get("/d",getUserDetails)
我在 thunderclient 中收到 {"error": "Server error"} 的错误
errorInfo: {
code: 'auth/user-not-found',
message: 'There is no user record corresponding to the provided identifier.'
}, 代码前缀:'auth' }
这是我从迅雷客户端发送GET请求时得到的错误
程序应该返回
[“美食”、“旅游”、“科技”、“电脑”、“汽车”]