'Firebase 9 - Trying to create a user document once a user successfully signs up

I can't get a document created once a user signs up. This is Firebase 9 so I'm not sure what is missing. The user gets created no problem.

SignupPage.tsx

  const handleSignup = async (values: SignupFields) => {
    const { email, password } = values;
    try {
      const userAuth = await createUserWithEmailAndPassword(
        auth,
        email,
        password
      );

      const newUserObject: FirebaseUserObject = {
        uid: userAuth.user.uid,
        username: '',
        email: email,
        emailVerified: false,
        photoUrl: '',
        joinDate: new Date().toString(),
      };

      createNewUserDocument(newUserObject);
    } catch (error: unknown) {
      if (error instanceof Error) setErrorState(error.message);
    }
  };

firebaseFunctions:

export const createNewUserDocument = async (user: FirebaseUserObject) => {
  await setDoc(doc(db, 'users', user.uid), user);
};

Firestore Rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}


Solution 1:[1]

may be you can add await to createNewUserDocument(newUserObject);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DiveDive