我具有此功能,可以在验证用户的电话号码后添加自定义声明
exports.phoneCustomClaim = functions.auth.user().onCreate((user) => {
const sellerNumber = user.phone; // here i am not getting the phone number
const uid = user.uid;
const customClaims = {
number: sellerNumber,
};
console.log(`Uid: ${uid}, number: ${sellerNumber}`);
console.log(`before Seller number: ${sellerNumber}`);
return admin.auth().setCustomUserClaims(uid, customClaims).then(() => {
console.log(`claim added!`);
})
.catch(error => {
console.log(error);
})
});
Log
Uid: 1mlxF1T8xcWbByAzQ7rfKjdshj, number: undefined
请获取该电话号码?
我怀疑在实际验证电话号码之前已创建(但未验证)用户帐户。这类似于电子邮件验证流程的工作方式。
如果是这种情况,则必须解决该问题。由于当前在更新用户个人资料时没有Cloud Functions触发器,因此,您最好的办法是在用户验证其电话号码后从代码中调用可调用的Cloud Function。