我正在尝试构建一个 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
});
最佳答案
要从 Cloud Functions 更新用户名,您将使用适用于 Node.js 用户的 Firebase Admin SDK。通过它,您可以使用类似这样的 update any properties of a user profile :
admin.auth().updateUser(uid, { email: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="731e1c171a151a16172600160133160b121e031f165d101c1e" rel="noreferrer noopener nofollow">[email protected]</a>', phoneNumber: '+11234567890', emailVerified: true, password: 'newPassword', displayName: 'Jane Doe', photoURL: 'http://www.example.com/12345678/photo.png', disabled: true }) .then(function(userRecord) { // See the UserRecord reference doc for the contents of userRecord. console.log('Successfully updated user', userRecord.toJSON()); }) .catch(function(error) { console.log('Error updating user:', error); });
关于node.js - 如何更改firebase云函数中的显示名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60419960/