首页 > 解决方案 > 为什么我得到一个函数而不是 Ionic 4 上 currentUser 的 UID 值?

问题描述

当我在一个应该返回当前用户的 uid 的方法上执行 console.log 时,它会返回该函数。为什么?

我尝试获取 UID 的不同方法:

  1. 这是当前用户的价值:

    function () {
        return this.afAuth.auth.currentUser.uid;
    }
    
  2. 这是当前用户的值:

    function () {
        return this.user.uid
     }
    

什么是正确的?为什么无法获得价值?当我创建用户 uid 时,方法是下一个:

  const res = await this.afAuth.auth
                .createUserWithEmailAndPassword(username, password)

  this.afstore.doc(`/users/${res.user.uid}`).set({
    username
  })

标签: angularionic4

解决方案


最终解决:

最后返回值的唯一方法是:

getUID() {
    return this.afAuth.auth.currentUser.uid
}

我按照错误的教程...


推荐阅读