在firestore中设置新的displayName,并使用Angular更新 [英] set in firestore the new displayName updated with Angular

查看:61
本文介绍了在firestore中设置新的displayName,并使用Angular更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hola开发人员正在使用带有角度和Firebase的此应用程序,我已经为用户创建的显示名称进行了更新,但现在尝试将其保留在我的Firestore中时出现了一些问题.

Hola developers being on this app with angular and firebase i already update my display name for user created , but now trying to keep that name in my firestore im having some issues.

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!!!
}

因此基本上在此服务中,我只是尝试通过在我的构造函数FirestoreModule中初始化的变量更新displayName的访问权限,然后通过到达我要设置该新名称的位置的路径(集合/doc)进行访问使用方法集,并访问在Firestore i中创建的密钥更新与我新的displayName,但不起作用.关于我该如何改善它的任何想法.谢谢!!!

thus basically in this service i just try to once the displayName is updated access through a variable initialized in my constructor the FirestoreModule, and then through the path(collection/doc) reaching to the place i want to set that new name i use the method set, and accessing the key created in firestore i updated with my new displayName, but doesnt work. Any idea about how could i improve this .Thanks in advance!!!

推荐答案

当您需要调用许多返回Promise的方法时,您可以进行异步/等待

when you need call many method who returns Promise you can do async/await example 1 and example 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;
    }

这篇关于在firestore中设置新的displayName,并使用Angular更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆