以下Google Cloud Function应该取消与特定用户的电话号码链接。如果代码是在客户端上执行的,则如下所示。但是,(currentUser)是未定义的,这是有道理的,因为云功能对当前用户一无所知。
我应该用(下面的currentUser-)替换什么?
const admin = require('firebase-admin');
module.exports = async function (request, response) {
/* eslint-disable */
admin.auth().getUserByPhoneNumber(request.body.phoneNo)
.then( (userRecord) => {
// WHAT SHOULD I REPLACE currentUser (BELOW) WITH?
admin.auth().currentUser.unlink(firebase.auth.PhoneAuthProvider.PROVIDER_ID)
.then ( () => {
console.log("getUserByPhoneNumber - unlink - then");
})
.catch( (error) => {
console.log("getUserByPhoneNumber - unlink - catch - error:", error);
})
;
response.send({ success: true });
})
.catch( (error) => {
console.log('getUserByPhoneNumber - catch - error:', error);
response.send({ success: false });
});
/* eslint-enable */
};
我尝试以下操作均未成功。
admin.auth().getUser(userRecord.uid).unlink(firebase.auth.PhoneAuthProvider.PROVIDER_ID)
admin.auth().userRecord.unlink(firebase.auth.PhoneAuthProvider.PROVIDER_ID)
感谢您的时间和精力为您提供帮助...
答案 0 :(得分:2)
如果您想通过Admin SDK从用户删除电话号码,请按以下步骤操作:
admin.auth().getUserByPhoneNumber(phoneNumber)
.then((userRecord) => {
return admin.auth().updateUser(userRecord.uid, {phoneNumber: null});
})
.then((userRecord) => {
// Phone number should be cleared from the user record.
})
.catch((error) => {
// Error occurred.
});