我正在尝试从firebase中的getUserRecordFromAuth
函数内部返回userRecord,并使用它从Firebase中的身份验证中获取用户的UID
。
问题是userRecord.uid总是返回undefined
,即使我在getUserRecordFromAuth()
中返回了promise的值。是什么给了什么?
const getUserData = mobile => {
const userRecord = getUserRecordFromAuth(mobile);
console.log('uid', userRecord.uid);
}
const getUserRecordFromAuth = mobile => {
const promise = auth.getUserByPhoneNumber(mobile);
return promise.then(userRecord => {
return userRecord;
}).catch(error => {
console.log(error);
});
}
答案 0 :(得分:2)
当您返回Promise以获得结果时,您需要使用.then()
const getUserData = mobile => {
getUserRecordFromAuth(mobile)
.then((userRecord) => console.log('uid', userRecord.uid));
}