我在一个项目中使用react-native-firebase v5.6。
目标:在注册流程中,我有用户输入他们的电话号码,然后我发送一个OTP到所说的电话号码。我希望能够将用户输入的代码与从Firebase发送的代码进行比较,以便能够将条目授予注册的下一个步骤。
问题:用户获得SMS OTP和所有内容,但是phoneAuthSnapshot对象由firebase.auth().verifyPhoneNumber(number).on('state_changed', (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发送的代码能够进行比较?
发布于 2021-08-01 05:40:07
为了使用多因素身份验证,您必须在后台创建电话登录提供商,与主(在您的情况下)电子邮件登录提供商一起使用,而用户选择更新设置并启用MFA。然后在用户使用电子邮件登录提供者登录时链接它,如下所示;
const credential = auth.PhoneAuthProvider.credential(verificationId, code);
let userData = await auth().currentUser.linkWithCredential(credential);https://stackoverflow.com/questions/59779991
复制相似问题