【问题标题】:Firebase Auth: updateProfile in Cloud Function?Firebase Auth:Cloud Function 中的 updateProfile?
【发布时间】:2018-02-13 20:05:41
【问题描述】:

我尝试在我的云函数中使用由 HTTPS 触发的 updateProfile()。

错误:

user.updateProfile 不是函数

云功能:

app.get("/user/create", (req, res) => {
    res.setHeader('Content-Type', 'application/json')

    admin.auth().verifyIdToken(req.query.token).then(user => {
        let name = req.query.name

        user.updateProfile({
            displayName: name
        }).then(() => {
            res.send(JSON.stringify({
                result: false,
                error: err.message
            }))
        })

    })
})

这个错误对我来说完全有道理,但我不知道如何获得实际的用户参考来更新个人资料,知道吗?

【问题讨论】:

    标签: javascript firebase firebase-authentication firebase-admin


    【解决方案1】:

    您似乎假设 verifyIdToken() 生成一个包含 User 对象的承诺。这不是这里的情况。根据the API docs,它提供了一个DecodedIdToken 对象。该对象包含一个 uid 属性,其中用户的 UID 由您传递给它的令牌表示。

    如果您想从那里获取UserRecord 对象,您可以使用该UID 调用admin.auth().getUser(uid)。但是,这无助于您更新用户的个人资料。

    如果您想更新给定 UID 的配置文件,您可以致电 admin.auth().updateUser(uid, properties)

    【讨论】:

      猜你喜欢
      • 2016-11-28
      • 2017-08-13
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2021-07-13
      • 2018-05-28
      • 2020-02-17
      • 2020-07-25
      相关资源
      最近更新 更多