react原生firebase手机身份验证-非常奇怪的行为



我几乎完全从他们的网站上复制了来自RNFB的电话身份验证代码。。。请参阅下面的代码(此处链接(

当我使用;用于测试的电话号码";Firebase提供的功能(即使用虚拟电话号码(。。。。那么当我运行signInWithPhoneNumber函数时,它不会在FB中创建用户。。。。。直到我运行CCD_ 2函数,它才在FB中创建用户。据我所知,这就是它的运作方式
无论如何。。。。当我使用自己的电话号码运行MyPhoneAuthButtonfn时(即"真实"测试(。。。则SMS认证消息被发送给我,并且在FB中立即创建用户而不必运行CCD_ 4fn。为什么它在测试和运行产品时表现不同?我应该为哪个流程编码?感谢的任何帮助

const MyPhoneAuthButton = props => {
const [objConfirm, setObjConfirm] = useState(null);
const [code, setCode] = useState('');
// Handle the button press
const signInWithPhoneNumber = phoneNumber => {
auth()
.signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
setObjConfirm(confirmResult);
})
.catch(err => {
console.log('Invalid Phone Number', err.message);
});
};
const confirmCode = () => {
objConfirm
.confirm(code)
.then(user => {
console.log('User auth by phone OK', user);
.catch(err => {
console.log('Invalid code.', err.message);
});
};

<MyButton
onPress={() => {
signInWithPhoneNumber(props.telNum);
}}>
Sign in With Phone Number
</MyButton>
const signInWithPhoneNumber = phoneNumber => {
auth()
.signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
console.log('User successfully authorized via telNum');
setObjConfirm(confirmResult);
})
.catch(err => {
Alert.alert('Invalid Phone Number', err.message);
console.log('Invalid Phone Number', err.message);
});
};

应该是这样的。您应该首先通过确认阶段,然后您将拥有代码确认按钮。我已经根据你从firebase 链接的url重新组织了它

const MyPhoneAuthButton = props => {
const [objConfirm, setObjConfirm] = useState(null);
const [code, setCode] = useState('');
// Handle the button press
const signInWithPhoneNumber = phoneNumber => {
auth()
.signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
setObjConfirm(confirmResult);
})
.catch(err => {
console.log('Invalid Phone Number', err.message);
});
};
const confirmCode = () => {
objConfirm
.confirm(code)
.then(user => {
console.log('User auth by phone OK', user);
.catch(err => {
console.log('Invalid code.', err.message);
});
};

const signInWithPhoneNumber = phoneNumber => {
auth()
.signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
console.log('User successfully authorized via telNum');
setObjConfirm(confirmResult);
})
.catch(err => {
Alert.alert('Invalid Phone Number', err.message);
console.log('Invalid Phone Number', err.message);
});
};
if(!objConfirm) {
return (
<MyButton
onPress={() => {
signInWithPhoneNumber(props.telNum);
}}>
Sign in With Phone Number
</MyButton>  
)
}

return (
<>
<TextInput value={code} onChangeText={text => setCode(text)} />
<Button title="Confirm Code" onPress={() => confirmCode()} />
</>
);

最新更新