皈依舞
2022-10-13 19:29:29
我正在嘗試將用戶保存到我的 Firestore 中的集合中。似乎正在創(chuàng)建用戶,我可以在Authentication選項卡中看到它們,但是它們沒有保存到我的 Firestore 內(nèi)的收藏中。我的控制臺內(nèi)似乎也沒有任何錯誤。我已經(jīng)為此苦苦掙扎了幾個小時,我什至不知道如何調(diào)試它。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條經(jīng)驗 獲得超6個贊
await從中刪除localStorage.setItem不是異步函數(shù)。
您還需要將 await 添加到db.collection("/users").doc(userUid)
這是您可以做的另一種方法。讓云功能為您處理。
每當創(chuàng)建用戶時,都會觸發(fā)以下功能。
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,
});
});
如果您需要有關(guān)云功能的更多信息,請閱讀以下內(nèi)容。
https://firebase.google.com/docs/functions/get-started
添加回答
舉報
0/150
提交
取消