javascript - Firestore auth,使用用户 UID 与 ionic 记录 id
问题描述
当用户注册时,我正在尝试使用用户 UID 作为文档的 ID。
在 service.ts 中,我有这一行:
create_NewStudent(record) {
return this.firestore.collection('users').add(record);
}
这是我的注册功能
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();
});
}
现在,当新注册时 -> 它会生成一个文档 ID,但是如何使用用户 uid 作为文档 ID
谢谢你的帮助
解决方案
使用 add() 将在随机生成的 id 下创建新文档。假设您有办法获取您的用户 ID。您可以使用
this.firestore.collection('users').doc(uid).set(record);
在注册时获取 uid
signup() {
this.afAuth.auth
.createUserWithEmailAndPassword(this.email, this.pass).then( token => {
console.log(token.user.uid)
});
推荐阅读
- sql-server - 将使用和加密密码的 SSIS 包从 2008 升级到 2012
- android - 使用 GridLayoutManager 使 RecyclerView 中的某些行具有更少的项目,并具有水平移位
- java - RxJava Single.just 在主线程中
- c++ - 实现 C++ grpc 异步客户端时如何轮询 CompletionQueue?
- amazon-web-services - 删除完整 S3 存储桶 CLI
- python - Apache Beam Python 单元测试 ParDo 类 with_outputs
- android - 是否可以从即时应用程序启动另一个应用程序?
- r - 如何在 R 中按 28 天期间和地区分组
- java - 无法将测试配置注入 Play!2.6 Guice 创建的应用
- docker - 如何使用 NGINX 配置 Angular 和 vuejs dockerized 应用程序