So I have been trying to implement the firebase phone auth in my react native project. I followed this great tutorial linked below but was facing issues with changing the confirmation section to be in a different page instead of the phone number input and code input all being on the same page. I get an error stating the verificationId was not found as its being called in the previous page.
If anyone can help out out, that would be great.
Thanks
const const Login = () => {
const navigation =useNavigation();
const [phoneNumber, setPhoneNumber] = useState();
const [verificationId, setVerificationId] = useState(null);
const recaptchaVerifier = useRef(null);
const sendVerification = () => {
try {
const phoneProvider = new firebase.auth.PhoneAuthProvider();
phoneProvider
.verifyPhoneNumber(phoneNumber, recaptchaVerifier.current)
.then(setVerificationId);
} catch (error) {
alert(error);
}
navigation.navigate('OTPScreen', { verificationId:
verificationId})
};
return(
OTP screen
const const OTPScreen = () => {
const verificationId = props.route.params.verificationId
const [code, setCode] = useState('');
const confirmCode = () => {
const credential =
firebase.auth.PhoneAuthProvider.credential(
verificationId,
code
);
firebase
.auth()
.signInWithCredential(credential)
.then((result) => {
console.log(result);
navigation.navigate('Home')
});
};
return(