简体   繁体   English

Firebase身份验证:Cloud Function中的updateProfile?

[英]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.

相关问题 updateProfile 不是 function (Firebase) - updateProfile is not a function (Firebase) 未处理的拒绝(类型错误):firebase_app__WEBPACK_IMPORTED_MODULE_18__.default.auth(...).updateProfile 不是 function - Unhandled Rejection (TypeError): firebase_app__WEBPACK_IMPORTED_MODULE_18__.default.auth(...).updateProfile is not a function auth.onAuthStateChanged 在 Firebase 中的 auth.currentUser.updateProfile 后未触发 - auth.onAuthStateChanged not triggering after auth.currentUser.updateProfile in Firebase 交易内部的firebase firestore wrap updateProfile函数 - firebase firestore wrap updateProfile function inside a transaction firebase.auth(...).signInWithEmailAndPassword 不是云中的 function Function - firebase.auth(...).signInWithEmailAndPassword is not a function in Cloud Function 如何在 firebase / Angular 中使用 updateProfile - How to use updateProfile in firebase / Angular Firebase 云功能 1.0,当前用户没有身份验证信息 - Firebase cloud function 1.0, no auth information for current user Firebase 云 function 带有对外部 api 的基本身份验证的获取请求 - Firebase cloud function with fetch request with basic auth to external api Firebase 休息身份验证 - 云函数 - Firebase rest auth - Cloud functions firebase - 每当用户注册时使用 updateProfile - firebase - Use updateProfile whenever a user signup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM