Firebaseで作成されたアカウントをphoneNumberでリンクする方法
✅私は、ユーザーが携帯電話使用数で自分のプロフィールを更新してみましょうすることができていますverifyPhoneNumber
し、更新currentUser.updatePhoneNumber
❌電話でのログインを許可し、新しいユーザーが電話番号でサインインしようとすると、アカウントが自動的に作成されるという問題が発生します。
その後、番号を電子メールアカウントに関連付ける必要がある場合、上記のメソッドはcredential-already-in-use
エラーを返します。
Firebaseは、ドキュメントで次の方法を推奨しています。
var credential = firebase.auth.PhoneAuthProvider.credential(confirmationResult.verificationId, code);
firebase.auth().signInWithCredential(credential);
だから私は一緒にこれをしました、linkWithCredential
しかしsignInWithCredentialは結果を返しますresult.credential = null
// Sign in user with the account you want to link to
auth.signInWithCredential(credential).then(function(result) {
console.log("Sign In Success", result);
var currentUser = result.user;
return prevUser.linkWithCredential(result.credential) //this line doesn't work.
.then(function(linkResult) {
return auth.signInWithCredential(linkResult.credential);
})
}).catch(function(error) {
console.log("Sign In Error", error);
});
result.credential = nullであるため、LinkWithCredentialを続行できません。
私も試しましlinkWithPhoneNumber
たが、検証IDが返されますが、それでもアカウントをマージできません。
❓phoneNumberアカウントを他のアカウント(Facebook / google / email)とどのようにマージしたか知っていますか?
回答
既存のアカウントを電話番号にリンクする場合は、を使用できますlinkWithPhoneNumber
。基本的に、ユーザーがサインインした後(たとえば、Googleで)、ユーザー情報を取得し、後でその資格情報を電話番号にリンクします。こちらの質問リンクに似た詳細な回答を見つけました
多分何かのような
const confirmationResult = await firebase.auth().currentUser.linkWithPhoneNumber(phoneNumber, recaptcha);
//Prompt your user for the code they recieved via sms here
confirmationResult.confirm(code);
ユーザー名/パスワード、Facebook googleなどを介してログインしたユーザーがいる場合は機能しますか?
電話リンクから確認IDを取得するのではなく、ConfirmationResultを取得するため