プロジェクトで_react-native-firebase
_ v5.6を使用しています。
目標:登録フローで、ユーザーに電話番号を入力してもらい、OTPをその電話番号に送信します。ユーザーが入力したコードとFirebaseから送信されたコードを比較して、登録の次のステップへのエントリを許可できるようにしたいと考えています。
問題:ユーザーはSMS OTPおよびすべてを取得しますが、firebase.auth().verifyPhoneNumber(number).on('state_changed', (phoneAuthSnapshot => {})
によって返されたphoneAuthSnapshot
オブジェクトは、次のコードの値を提供しませんfirebaseが送信されたため、ユーザーが入力したコードと比較するものは何もありません。ただし、verificationId
プロパティには値があります。上記のメソッドから返されるオブジェクトは次のとおりです:
_'Verification code sent', {
verificationId: 'AM5PThBmFvPRB6x_tySDSCBG-6tezCCm0Niwm2ohmtmYktNJALCkj11vpwyou3QGTg_lT4lkKme8UvMGhtDO5rfMM7U9SNq7duQ41T8TeJupuEkxWOelgUiKf_iGSjnodFv9Jee8gvHc50XeAJ3z7wj0_BRSg_gwlN6sumL1rXJQ6AdZwzvGetebXhZMb2gGVQ9J7_JZykCwREEPB-vC0lQcUVdSMBjtig',
code: null,
error: null,
state: 'sent'
}
_
これが私の画面上の実装です:
_firebase
.firestore()
.collection('users')
.where('phoneNumber', '==', this.state.phoneNumber)
.get()
.then((querySnapshot) => {
if (querySnapshot.empty === true) {
// change status
this.setState({ status: 'Sending confirmation code...' });
// send confirmation OTP
firebase.auth().verifyPhoneNumber(this.state.phoneNumber).on(
'state_changed',
(phoneAuthSnapshot) => {
switch (phoneAuthSnapshot.state) {
case firebase.auth.PhoneAuthState.CODE_SENT:
console.log('Verification code sent', phoneAuthSnapshot);
this.setState({ status: 'Confirmation code sent.', confirmationCode: phoneAuthSnapshot.code });
break;
case firebase.auth.PhoneAuthState.ERROR:
console.log('Verification error: ' + JSON.stringify(phoneAuthSnapshot));
this.setState({ status: 'Error sending code.', processing: false });
break;
}
},
(error) => {
console.log('Error verifying phone number: ' + error);
}
);
}
})
.catch((error) => {
// there was an error
console.log('Error during firebase operation: ' + JSON.stringify(error));
});
_
Firebaseから送信されたコードを比較できるようにするにはどうすればよいですか?
残念ながら、これはfirebaseではサポートされていません。 signInWithCredentialの後のログインとログアウトは機能しますが、非常に混乱します