Jame Brown
Jame Brown

Reputation: 3

Cannot initialize Firebase admin sdk in Cloud Functions

I am trying to create a Firebase Cloud Function that uses the firebase admin SDK. However, when I deploy the function below and attempt the function I receive the error "INTERNAL". In the logs on the Firebase dashboard I am seeing:

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

What am I missing? Thanks in advance.

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

This is how I am calling it on my client:

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

Upvotes: 0

Views: 229

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

The correct syntax is admin.auth().updateUser(... with parentheses after auth.

Upvotes: 1

Related Questions