我正在嘗試從 firebase 獲取特定檔案。如果存在,那就太好了。但如果沒有,我不希望它破壞我的應用程式。我只是想讓它繼續前進。但是,我似乎無法擺脫這個錯誤:
我的錯誤
這是我的代碼:
async function getOtherInfo() {
//get profile image, username if they exist
const profileRef = doc(db, "profiles", email);
const snap = await getDoc(profileRef);
if (snap.exists()) {
setProfileImg(snap.data().profileImg);
setUserName(snap.data().userName);
}
Firebase 大師,請幫助我,我很快就會發瘋。謝謝一堆。
編輯:添加代碼部分以顯示我的資料庫和電子郵件狀態的來源。兩者都是有效的。
//init services
const db = getFirestore();
const [email, setEmail] = useState(identifier.email)
uj5u.com熱心網友回復:
如果認為您正在尋找:
if (email) { // ??
//get profile image, username if they exist
const profileRef = doc(db, "profiles", email);
const snap = await getDoc(profileRef);
if (snap.exists()) {
setProfileImg(snap.data().profileImg);
setUserName(snap.data().userName);
}
這確保您僅在實際存在值email時才嘗試加載檔案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/516633.html
標籤:Google Cloud Collective javascript火力基地谷歌云火库
