title: Creating users is jumping one step in Cloud Functions
body: <p>So I'm using Cloud Functions to persist data in Firestore, the problem comes with the inconsistency on the update line, when I execute the function, sometimes it really doesn't updates the UID (which I set up like userRecord.uid), it just skips like it was absolutely nothing, making me absolutely mad af!</p>
  
  <p>Https callable function</p>
  
  <pre><code>   exports.createUser = functions.https.onCall((data, context) =&gt; {
  
        return isAdmin(context.auth.uid)
        .then(result =&gt; {
  
          if(result === false) {
  
            return "Você não possui acesso a essa função";
  
          }
  
          return createUser(data.usuario);
  
        })
        .catch(error =&gt; {
  
          return error.message;
  
        });
  
      });
  
      function createUser(usuario:Usuario): Promise&lt;void&gt; {
  
        let uid;
  
        return admin.auth().createUser({
  
          email: usuario.email,
          password: usuario.senha,
  
        })
        .then(userRecord =&gt; {
  
          uid = userRecord.uid;
  
          userRole(usuario.role, userRecord);
  
        })
        .then(() =&gt; {
  
          db.collection('usuario').doc(uid).set(usuario); 
  
        })
        .then(() =&gt; {
  
          db.doc('usuario/'+uid).update({uid:uid});
  
        })
        .then(()  =&gt; {
  
          return 'O usuário '+`${usuario.nomeCompleto} `+'foi cadastrado com sucesso, recebendo o acesso de '+`${usuario.role}`;
  
        })
        .catch(error =&gt; {
  
          return error.message;
  
        });
  
      }
  
      function isAdmin(uid) {
  
        return admin.auth().getUser(uid)
        .then(userRecord =&gt; {
  
          if(userRecord.customClaims.admin === true) {
            return true;
          }
  
          return false;
  
        })
        .catch(() =&gt; {
  
          return false;
  
        });
  
      }
  
      function userRole(usuario:string, userRecord) {
  
        if(usuario === 'Vendedor') {
  
          adm.setCustomUserClaims(
            userRecord.uid, {vendedor: true}
          );
  
        } else if(usuario ==='Admin') {
  
          adm.setCustomUserClaims(
            userRecord.uid, {admin: true}
          );
  
        } else if(usuario ==='Supervisor') {
  
          adm.setCustomUserClaims(
            userRecord.uid, {supervisor: true}
          );
  
        } else if(usuario ==='Faturamento') {
  
          adm.setCustomUserClaims(
            userRecord.uid, {faturamento: true}
          );
  
        }
  
      }
  </code></pre>
  
  <p>variable in app class</p>
  
  <pre><code>   createUser = firebase.functions().httpsCallable('createUser');
  </code></pre>
  
  <p>function that receive the values</p>
  
  <pre><code>    cadastrarUsuario() {
  
        const usuario = this.formCriarUsuario.value;
        const id = this.db.createId();
  
        this.createUser({usuario, id}).then(result =&gt; {
  
          this.toast.toastMessage(result.data);
  
        }). catch(error =&gt; {
  
          this.toast.errorToast('Erro ao cadastrar usuário', error.message);
  
        });
  
      }
  </code></pre>