亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

firebase/firestore 將用戶保存到集合

firebase/firestore 將用戶保存到集合

皈依舞 2022-10-13 19:29:29
我正在嘗試將用戶保存到我的 Firestore 中的集合中。似乎正在創建用戶,我可以在Authentication選項卡中看到它們,但是它們沒有保存到我的 Firestore 內的收藏中。我的控制臺內似乎也沒有任何錯誤。我已經為此苦苦掙扎了幾個小時,我什至不知道如何調試它。export const authMethods = {  signup: (email, password, setErrors, setToken) => {    firebase      .auth()      .createUserWithEmailAndPassword(email, password)      // make res asynchronous so that we can make grab the token before saving it.      .then(async res => {        const token = await Object.entries(res.user)[5][1].b        // set token to localStorage        await localStorage.setItem('token', token)        // grab token from local storage and set to state.        setToken(window.localStorage.token)        const userUid = firebase.auth().currentUser.uid        const db = firebase.firestore()        db.collection('/users')          .doc(userUid)          .set({            email,            password,          })        console.log(res)      })      .catch(err => {        setErrors(prev => [...prev, err.message])      })  }, ....}有任何想法嗎?
查看完整描述

1 回答

?
肥皂起泡泡

TA貢獻1829條經驗 獲得超6個贊

await從中刪除localStorage.setItem不是異步函數。


您還需要將 await 添加到db.collection("/users").doc(userUid)


這是您可以做的另一種方法。讓云功能為您處理。


每當創建用戶時,都會觸發以下功能。


export const onUserCreate = functions.auth

  .user()

  .onCreate(async (user, context) => {

    await admin.firestore().collection("users").doc(user.uid).set({

      id: user.uid,

      emailAddress: user.email,

      verified: user.emailVerified,

    });

  });

如果您需要有關云功能的更多信息,請閱讀以下內容。


https://firebase.google.com/docs/functions/get-started


查看完整回答
反對 回復 2022-10-13
  • 1 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號