I have an application that you can log in to by phone number
After entering the phone number I receive an SMS code
A new screen opens where I can enter this code
When I enter the code, I get information that the code is expired
Sign: First screen
onSignIn() {
const {code, phoneNumber} = this.state;
const newNumber = '+' + code + phoneNumber;
if (newNumber.length > 10) {
firebase
.auth()
.signInWithPhoneNumber(newNumber)
.then(confirmResult => {
this.setState({result: confirmResult});
const navigateAction = NavigationActions.navigate({
routeName: 'SecurityCode',
params: {phoneAuthResponse: confirmResult},
});
this.props.navigation.dispatch(navigateAction);
})
.catch(error => {
if (error.message === 'TOO SHORT') {
alert('Please enter a valid phone number');
} else {
alert(error.message);
}
});
} else {
alert('Please Enter Your Number');
}
}
Confirm: Second screen
onConfirmCode() {
const {securityCode} = this.state;
if (securityCode.length > 5) {
this.props.navigation.state.params.phoneAuthResponse
.confirm(securityCode)
.then(async user => {
const ref = firebase.database().ref(`users/${user.uid}`);
ref.once('value', async snapshot => {
let data = snapshot.val();
if (!data) {
this.props.navigation.navigate('CreateProfile', {
user: {uid: user.uid, phone_number: user.phoneNumber},
});
} else {
this.props.reduxLoginUser(data);
this.props.navigation.navigate('InviteContacts');
}
});
})
.catch(error => console.warn(error.message));
} else {
alert('Please enter the 6 digit code');
}
}
What is done wrong?