【发布时间】:2020-06-10 16:23:24
【问题描述】:
我正在尝试构建一个 firebase 云函数来更改显示名称。
我知道我可以在 android 中轻松做到这一点,但是因为每次我更改显示名称时我都需要更新所有用户记录,而且似乎没有办法在显示名称时在 firebase 函数中获得通知已更改(如果我错了请纠正我),我计划在 firebase 中进行更改,同时更新记录。
我就是这样开始的......
exports.changeDisplayName = functions.https.onCall((data,context) => {
console.log(`User ${context.auth.uid} has requested to change its display name`);
//If user not authenitacted, throw an error
if (!(context.auth && context.auth.token && (context.auth.token.firebase.sign_in_provider === 'phone'))) {
if (!context.auth) {
console.log(`User ${context.auth.uid} without auth`);
}
if (!context.auth.token) {
console.log(`User ${context.auth.uid} without token`);
}
if (!context.auth.token.phoneNumber) {
console.log(`User ${context.auth.uid} without phone number (${context.auth.token.firebase.sign_in_provider})`);
}
throw new functions.https.HttpsError(
'permission-denied',
'Must be an authenticated user with cellphone to change display name'
);
}
// Change display display name from data
// update firebase contacts
});
【问题讨论】:
-
你有什么问题?听起来你只需要完成你的功能。
标签: node.js firebase-authentication google-cloud-functions