在Firestore中设置新的显示名称更新为角度



Hola开发人员在这个带有Angular和Firebase的应用程序上,我已经更新了用户创建的显示名称,但现在试图将该名称保留在我的Firestore中,我遇到了一些问题。

Service class where in i access my firstore and my fireauth modules
export class LoginService {
constructor(
private userLogin: AngularFireAuth,
private docCreator: AngularFirestore
) {}
signUpUser(emailUser: string, passwordUser: string) {
return new Promise((response, reject) => {
this.userLogin
.createUserWithEmailAndPassword(emailUser, passwordUser)
.then(
(responseOk) => {
this.userdata.uid = responseOk.user.uid;
this.userdata.restData = responseOk.user;
responseOk.user.updateProfile({
displayName: 'nameUpdated'
}).then(() => {
console.log('displayname setted');
response(responseOk);
});
let userDoc = this.docCreator
.collection('users')
.doc(responseOk.user.uid);===variable accessing my collection and doc of user created====
userDoc.set({
amountInAccount: 0,
userName:responseOk.user.displayName(HERE THE ISSUE)
});===trying to store in my new user created doc the displayname already updated====FAIL!!!
}

因此基本上在这个服务中,我只是尝试在 displayName 更新后通过在我的构造函数 FirestoreModule 中初始化的变量访问,然后通过路径(集合/文档(到达我想设置新名称的地方,我使用方法集,并访问在 Firestore i 中创建的键 使用我的新显示名称进行了更新,但不起作用。 关于我如何改进这一点的任何想法.提前谢谢!!

当你需要调用许多方法时,谁返回承诺你可以做异步/等待示例 1 和示例 2

async createUser(emailUser: string, passwordUser: string) {
const responseOk = await this.auth
.createUserWithEmailAndPassword(emailUser, passwordUser);
this.userdata.uid = responseOk.user.uid;
this.userdata.restData = responseOk.user;
await responseOk.user.updateProfile({
displayName: displayName
});
console.log('displayname setted', responseOk.user.displayName);
let userDoc = this.docCreator
.collection('users')
.doc(responseOk.user.uid);
await userDoc.set({
amountInAccount: 0,
userName: responseOk.user.displayName
});
console.log('userDoc setted');
return responseOk;
}

相关内容

  • 没有找到相关文章

最新更新