[英]Firebase Auth: updateProfile in Cloud Function?
I tried to use updateProfile() in my Cloud Function, triggered by HTTPS. 我试图通过HTTPS触发在Cloud Function中使用updateProfile()。
Error: 错误:
user.updateProfile is not a function
user.updateProfile不是函数
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? 该错误对我完全有意义,但是我不知道如何获得实际的用户参考来更新配置文件,有什么想法吗?
It looks like you're assuming that verifyIdToken() generates a promise that contains a User object. 看起来您好像假设verifyIdToken()生成了一个包含User对象的promise。 That's not the case here.
这里不是这样。 According to the API docs , it provides a DecodedIdToken object.
根据API文档 ,它提供了DecodedIdToken对象。 That object contains a uid property with the UID of the user represented by the token you passed to it.
该对象包含一个uid属性,该用户的UID由传递给它的令牌表示。
If you want to get a UserRecord object from there, you can call admin.auth().getUser(uid) with that UID. 如果要从那里获取UserRecord对象,可以使用该UID调用admin.auth()。getUser(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) . 如果要更新给定UID的配置文件,则可以调用admin.auth()。updateUser(uid,properties) 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.