nic*_*rke 21 firebase google-cloud-functions
花了一段时间寻找一个似乎是一个简单问题的解决方案,但是......如何在云功能中获取当前用户的详细信息(何时不使用functions.auth触发器)?我相信必须有一个简单的解决方案.(我希望)
感谢您的回复...刚刚完成了但是如何在存储触发事件中从Firebase数据库中获取/ user/uid?例如
exports.addUploadInfoToDatabase = functions.storage.object().onChange(event => {
console.log("firebase storage has been changed");
// need to find the uid in here somehow
admin.database().ref(`/user/uid`).push({testKey:"testData"});
})
Run Code Online (Sandbox Code Playgroud)
如果我错过了你的回复中的重点,那就是Applogies.
谢谢...
Kim*_*Kim 17
首先,您可以通过呼叫用户来获取当前登录的用户tokenId getIdToken():https://firebase.google.com/docs/reference/js/firebase.User#getIdToken
firebase.auth().currentUser.getIdToken(true)
.then(function (token) {
// You got the user token
})
.catch(function (err) {
console.error(err);
});
Run Code Online (Sandbox Code Playgroud)
然后将其发送到您的云功能.
然后在您的云功能中,您可以使用:https://firebase.google.com/docs/auth/admin/verify-id-tokens
例:
admin.auth().verifyIdToken(idToken)
.then(function(decodedToken) {
var uid = decodedToken.uid;
// ...
}).catch(function(error) {
// Handle error
});
Run Code Online (Sandbox Code Playgroud)
decodeToken的文档位于:https://firebase.google.com/docs/reference/admin/node/admin.auth.DecodedIdToken#uid
DecodedIdToken包含用户uid,然后您可以通过以下方式告知用户:https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#getUser
返回UserRecord https://firebase.google.com/docs/reference/admin/node/admin.auth.UserRecord
| 归档时间: |
|
| 查看次数: |
11265 次 |
| 最近记录: |