phoneNumber로 만든 계정을 Firebase에 연결하는 방법
✅ 사용자가 사용 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 등을 통해 로그인 한 사용자가있는 경우 작동합니까?
Phone Linking에서 확인 ID가 아니라 ConfirmationResult를 얻으므로