Firebase身份验证电话号码 [英] Firebase Authentication Phone Number

查看:44
本文介绍了Firebase身份验证电话号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,我买了一张新的Chip Sim卡.然后,我尝试在某些应用程序中注册该电话号码,但出现错误:该凭据已与其他用户帐户关联.

Imagine that I bought a new Chip Sim Card. Then I tried to register this phone number in some application, but I get an error: This credential is already associated with a different user account.

如何取消链接/删除较旧的电话提供商以在最新帐户上使用它?

How can I unlink / delete the older phone provider to use it on the newest account?

谢谢!

推荐答案

我已经使用Google Cloud上的Rest函数解决了这个问题.当我收到错误1705(此凭据...)时,我打电话给我的服务,然后重试.

I've solved this using an Rest Function on Google Cloud. When I got the error 1705 (This credential...) I call my service and Then try again.

exports.removeUserPhone = functions.https.onRequest((req, res) => {

const phoneNumber = req.query.phoneNumber || req.body.phoneNumber
console.log("Phone Number:", phoneNumber);

var ret = { 
    success : true,
    result  : ""
};

admin.auth().getUserByPhoneNumber(phoneNumber)
.then(userRecord => {
    console.log("Successfully fetched user data:", userRecord.toJSON());

    admin.auth().updateUser(userRecord.uid, {
        phoneNumber: null
    })
    .then(userRecord2 => {
        ret.result = "Successfully updated user."
        res.send(ret)
        // See the UserRecord reference doc for the contents of userRecord.
        console.log("Successfully updated user", userRecord2.toJSON());
    })
    .catch(error => {
        ret.success = false
        ret.result  = "Error updating user."
        res.send(ret)
        console.log("Error updating user:", error);
    });
 })
 .catch(error => {
    ret.success = false
    ret.result  = "Error fetching user data."
    res.send(ret)
    console.log("Error fetching user data:", error);
    });
});

Idk,如果这是最好的方法,但是效果很好.

Idk if it's the best way, but it's working perfectly.

这篇关于Firebase身份验证电话号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆