Reputation: 1
Invalid collection reference. Collection references must have an odd number of segments, but profiles/undefined has 2.
const user = await signUpNewUser(auth, email, password);
const docRef = await addDoc(collection(db, `profiles/${user.uid}`), {
nama: form.nama,
createdAt: new Date().getTime().toString(),
});
console.log("Document written with ID: ", docRef.id);
Upvotes: 0
Views: 196
Reputation: 598827
When you call addDoc
Firestore generates the ID for the new document for you. If you want to specify the ID yourself (as you do with user.uid
), use setDoc
instead:
const docRef = await setDoc(collection(db, `profiles/${user.uid}`), {
nama: form.nama,
createdAt: new Date().getTime().toString(),
});
Also see the Firebase documentation on setting a document.
Upvotes: 1