對于課堂上的專案,我們需要通過 Google 提供商創建帳戶。登錄后,您可以創建專案等,并將它們保存到您的帳戶中。問題是,一旦您重新登錄,setDoc 我用來創建新用戶的接縫會重疊我的getDoc功能。我的老師還指定不使用 get() 或 find() 出于某種原因。謝謝!
這是我嘗試過的,但沒有得到任何好的結果:
const docRef = doc(db, 'membres', creds.user.uid);
//faire une condition si le id existe dans la base de donner
//si oui, getdoc
//sinon, setdoc
if (docRef.exists) {
console.log('it exists!');
await getDoc(docRef);
} else {
console.log('No such document exists!');
await setDoc(docRef, {
nom: creds.user.displayName,
email: creds.user.email,
projets: [],
contacts: []
});
}
uj5u.com熱心網友回復:
該doc()函式回傳一個DocumentReference并且不獲取檔案或檢查它是否存在。您必須首先使用getDoc(docRef)獲取檔案,然后檢查該檔案是否存在。
由于不允許使用,因此只有在用戶第一次登錄時getDoc()才能添加檔案(使用)。setDoc()嘗試:
const result = await signInWithPopup(auth, provider);
const {isNewUser} = getAdditionalUserInfo(result) // <-- or result of signInWithRedirect();
if (isNewUser) {
// user has signed in first time
// setDoc(...)
} else {
// Existing user, document created already.
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/532401.html
標籤:Google Cloud Collective javascript火力基地谷歌云火库
上一篇:MVC表單資料無法系結到模型
