[英]FIREBASE phoneAuth ( LinkWithPhoneNumber ) . How to change a user's linked phone number later in Firebase Web. ( nodejs, Create-react-app )?
我在我的 create-react-app 項目中使用了 firebase。 出於注冊目的,我使用firebaseAuth().createUserWithEmailAndPassword(email, password)
然后在注冊后,我將他們的電話號碼保存在 localStorage 中,然后使用此功能將它們重定向到 PhoneAuth 頁面
export function PhnAuth(phone) {
window.recaptchaVerifier = new firebaseAuth.RecaptchaVerifier('recaptcha-container',{'size': 'small'});
return firebaseAuth().currentUser.linkWithPhoneNumber(phone, window.recaptchaVerifier)
.then(function (confirmationResult) {
window.confirmationResult = confirmationResult;
}).catch(function (error) {
})
}
在重新驗證並完成所有操作后,我成功地將用戶的電子郵件與他們的電話號碼相關聯。 但是稍后如何更新該電話號碼? 我在文檔中找不到有關更新鏈接電話號碼的任何信息。
updatePhoneNumber
, User
對象上有一個updatePhoneNumber
方法。
請參閱參考文檔和有關更新用戶配置文件的文檔。
請注意,為此您需要一個phoneCredential
,這意味着這必須是經過驗證的電話號碼。 查看如何在 firebase.auth (js, ts) 中更新用戶電話號碼。
如果您想在不驗證的情況下更新用戶的電話號碼,可以通過 Admin SDK 完成。 有關此示例,請參閱如何在 NodeJS 中更新 Firebase 身份驗證的電話號碼?
我試圖使用updatePhoneNumber API。 為了獲得電話憑證,我認為您必須獲得帶有新電話號碼的驗證碼。 因此,我必須使用帶有新電話號碼的verifyPhoneNumber API。 嘗試這樣做。
您需要取消當前手機的鏈接(provider.providerId === 'phone')
然后您可以鏈接一個新(provider.providerId === 'phone')
const currentUser = firebaseAuth().currentUser;
currentUser.unlink('phone').then(successCallback).catch(errorCallback)
要檢查手機是否鏈接到當前用戶,您需要檢查提供商列表
const phoneProviders = currentUser.providerData.filter(
provider => provider.providerId === 'phone'
);
if (phoneProviders.length > 0) {
currentUser.unlink('phone').then(successCallback).catch(errorCallback);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.