Firebase setDoc() 不创建文档

Slu*_*ord 5 javascript firebase reactjs firebase-authentication google-cloud-firestore

我正在使用 auth 创建一个新用户,该用户正在工作,然后使用新创建的 uid 创建一个具有相同内容的新文档。

const currentUser = await auth.createUserWithEmailAndPassword(email, pass);
        console.log('user registered')
        await setDoc(doc(db, "users", currentUser.user.uid),{
            forname: "Peter",
            surname: "Parker"
        })
        console.log('user profile added')
    dispatch({type:'USER_REG', payload: currentUser});
Run Code Online (Sandbox Code Playgroud)

当我收到控制台日志时,reg 进程会毫无问题地启动,然后程序只是等待,就像 setDoc 正在运行但从未完成,我不知道为什么。任何帮助表示赞赏。

小智 -1

尝试:

import { getAuth, signInWithEmailAndPassword } from "firebase/auth";

const auth = getAuth();
await auth.createUserWithEmailAndPassword(auth, email, pass).then(async(userRec)=>{
    const user = userRec.user;
    await await setDoc(doc(db, "users", user.uid),{
        forname: "Peter",
        surname: "Parker"
    }).catch((error)=>{
        console.log(error);
    });
}).catch((error)=>{
    console.log(error);
});
Run Code Online (Sandbox Code Playgroud)