i'm trying to use user UID for id of a doc when an user is signup.
in service.ts, I have this line :
create_NewStudent(record) {
return this.firestore.collection('users').add(record);
}
And this is my signup function
signup() {
this.afAuth.auth
.createUserWithEmailAndPassword(this.email, this.pass)
.then( token => {
console.log(token.user.uid)
});
let record = {};
record['nom'] = this.nom;
record['prenom'] = this.prenom;
record['email'] = this.email;
record['pass'] = this.pass;
record['datenaissance'] = this.datenaissance;
record['lieunaissance'] = this.lieunaissance;
record['adresse'] = this.adresse;
record['codepostal'] = this.codepostal;
record['ville'] = this.ville;
record['tel'] = this.tel;
record['secu'] = this.secu;
record['equipe'] = this.equipe;
record['poste'] = this.poste;
this.UsersService.create_NewStudent(uid,record).then(resp => {
this.nom = "";
this.prenom = "";
this.email = "";
this.pass = "";
this.datenaissance = "";
this.lieunaissance = "";
this.adresse = "";
this.codepostal = "";
this.ville = "";
this.tel = "";
this.secu = "";
this.equipe = "";
this.poste = "";
console.log(resp);
})
.then(() => {
this.modalCtrl.dismiss();
});
}
For now, when new signup -> it's generate an doc id, but how to use user uid as doc id
Thanks you for help
using add() will create the new document under a randomly generated id. Assuming you have a way to get your user id. You can put it into firestore using
this.firestore.collection('users').doc(uid).set(record);
To get the uid at signup
signup() {
this.afAuth.auth
.createUserWithEmailAndPassword(this.email, this.pass).then( token => {
console.log(token.user.uid)
});
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.