无法在Cloud Functions中初始化Firebase管理员SDK

时间:2019-10-11 01:34:21

标签: node.js firebase firebase-authentication firebase-admin

我正在尝试创建一个使用firebase admin SDK的Firebase Cloud Function。但是,当我在下面部署函数并尝试使用该函数时,会收到错误“ INTERNAL”。在Firebase仪表板上的日志中,我看到:

Unhandled error TypeError: admin.auth.updateUser is not a function

我想念什么?预先感谢。

const functions = require('firebase-functions')
const admin = require('firebase-admin')

admin.initializeApp()

exports.updateUser = functions.https.onCall((data, context) => {
  admin.auth
    .updateUser({
      email: data.email,
      displayName: data.name,
      emailVerified: true
    })
    .then(userRecord => userRecord.uid)
    .catch(err => {
      throw new functions.https.HttpsError('unknown', err)
    })
})

这是我在客户端上调用它的方式:

const updateUser = functions.httpsCallable('updateUser')
    updateUser({
      name: this.state.name,
      email: this.state.email,
      track: this.state.track,
      password: this.state.password
    })
      .then(res => {
        console.log(res)
      })
      .catch(err => {
        console.log(err)
      })

1 个答案:

答案 0 :(得分:1)

正确的语法是admin.auth().updateUser(...,并在auth后面加上括号。