I'm using firebase to authenticate my users, but when I ask firebase to authenticate via SMS, it sends double SMS to the user.
Sometimes the SMSs are identical, but sometimes it contains different codes.
Here is my Code:
`
sendCode() {
if (this.state.sendMessage) {
setTimeout(async () => {
try {
firebase.auth()
.verifyPhoneNumber("+972" + this.state.phone)
.on('state_changed', (phoneAuthSnapshot) => {
switch (phoneAuthSnapshot.state) {
// ------------------------
// IOS AND ANDROID EVENTS
// ------------------------
case firebase.auth.PhoneAuthState.CODE_SENT: // or 'sent'
firebase.auth().signInWithPhoneNumber("+972" + this.state.phone)
.then(confirmResult => this.setState({
confirmResult,
showCodeVerify: true,
message: 'Code has been sent!' }))
.catch(error => this.setState({ message: `Sign In With Phone Number Error: ${error.message}` }));
this.setState({ verificationCode: phoneAuthSnapshot.code })
break;
case firebase.auth.PhoneAuthState.ERROR: // or 'error'
console.log('verification error');
//alert(phoneAuthSnapshot.error);
break
}
}, (error) => {
// optionalErrorCb would be same logic as the ERROR case above, if you've already handed
// the ERROR case in the above observer then there's no need to handle it here
console.log(error);
// verificationId is attached to error if required
console.log(error.verificationId);
}, (phoneAuthSnapshot) => {
// and there'd be no need to ask for user input of the code - proceed to credential creating logic
// - if ANDROID auto verify timed out then phoneAuthSnapshot.code would be null, just like ios, you'd
// continue with user input logic.
console.log(phoneAuthSnapshot);
});
// optionally also supports .then & .catch instead of optionalErrorCb &
// optionalCompleteCb (with the same resulting args)
}
catch (err) {
setTimeout(() => {
//Alert.alert('Oops!', err.message);
}, 100);
}
})
}
Environment:
OS: macOS Sierra 10.12.6
Node: 8.9.1
Yarn: Not Found
npm: 5.5.1
Watchman: Not Found
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.1 AI-173.4670197
@Gshock1 I'm afraid that this is going to be an error in your implementation and you'll be calling the RNFirebase API twice somehow. Closing as it's not a react-native-firebase issue.
Hi,
I'm using firebase to authenticate my users, but when I ask firebase to authenticate via SMS, it sends double SMS to the user. Sometimes the SMSs are identical, but sometimes it contains different codes.
Here is my Code:
` sendCode() { if (this.state.sendMessage) { setTimeout(async () => {
} ' ' _verifyCode = () => {
/ try { firebase.auth.currentUser.linkWithCredential(firebase.auth.FacebookAuthProvider.credential(myState.state.UserToken)); } catch (error) { console.log("error trying to link 2 accounts") return true; } /
} '
Environment: OS: macOS Sierra 10.12.6 Node: 8.9.1 Yarn: Not Found npm: 5.5.1 Watchman: Not Found Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.1 AI-173.4670197
Packages: (wanted => installed) react: 16.0.0-beta.5 => 16.0.0-beta.5 react-native: 0.49.1 => 0.49.1 "react-native-firebase": "^3.1.0",