bonblow
bonblow

Reputation: 1189

Firebase Auth: updateProfile in Cloud Function?

I tried to use updateProfile() in my Cloud Function, triggered by HTTPS.

Error:

user.updateProfile is not a function

Cloud Function:

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

    })
})

The error makes totally sense to me, but I've no clue how I can get a actual user reference to update the profile, any idea?

Upvotes: 0

Views: 922

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317712

It looks like you're assuming that verifyIdToken() generates a promise that contains a User object. That's not the case here. According to the API docs, it provides a DecodedIdToken object. That object contains a uid property with the UID of the user represented by the token you passed to it.

If you want to get a UserRecord object from there, you can call admin.auth().getUser(uid) with that UID. However, that won't help you update the user's profile.

If you want to update the profile for a given UID, you can call admin.auth().updateUser(uid, properties).

Upvotes: 4

Related Questions