I'm doing a simple user creation, but the id field in the firestore is null and the ids are different.
why is this happening? how to solve?
code below:
const auth = await authFB().createUserWithEmailAndPassword(data.email, data.password);
const db = firestore();
await db
.collection('Clients')
.doc(auth.user.uid)
.set({
id: auth.user.uid,
name: {
first: firstName,
last: lastName
}
});
Document image below: (Look at id: null):
The solution is to create const uid = auth.user.uid
and use this constant in two paces inside firestore update. For example:
const auth = await authFB().createUserWithEmailAndPassword(data.email, data.password);
const uid = auth.user.uid; // <----
const db = firestore();
await db
.collection('Clients')
.doc(uid) // <----
.set({
id: uid, // <----
name: {
first: firstName,
last: lastName
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.