Hi, I need some assistance with storing user credentials in Firestore after they sign up. Unfortunately, I keep encountering the following error:
Invalid collection reference. Collection references must have an odd number of segments, but userDatabase/QMJiHnhoCchs6MKmPFk7wzTrlau1 has 2.
Below is a snippet of my code. Any help would be greatly appreciated!
const db = getFirestore(app)
//Sign up User Method
createUserWithEmailAndPassword(auth, email, password)
.then((res) => {
// Signed in
const uid = res.user.uid;
const data = {
id: uid,
email,
name,
};
const ref = collection(db, 'userDatabase', uid)
console.log(ref);
setDoc(ref, data)
.then(() => console.log("Created New User Document Successfully"))
.catch((e) => console.log("Error", e));
).catch((e) => console.log(e))
By trial and error, I discovered that the issue stemmed from this particular line of code:
const ref = collection(db, 'userDatabase', uid)
I'm unable to pinpoint the exact reason behind it despite trying various solutions. If you can shed some light on this problem, it would be immensely helpful.
createUserWithEmailAndPassword(auth, email, password)
.then((res) => {
// Signed in
const uid = res.user.uid;
// const data = {
// id: uid,
// email,
// name,
//};
const ref = collection(db, 'userDatabase', uid)
console.log(ref);
//setDoc(ref, data)
// .then(() => console.log("Created New User Document Successfully"))
// .catch((e) => console.log("Error", e));