I am using React Native with Expo. I'm trying to create phone authentication for my app using Firebase and the following function should throw an error according to the signInWithCredential documentation if you put a wrong verificationCode. However the function just logs a null user value and throws no error.
const confirmPhoneVCode = async () => {
try {
const credential = PhoneAuthProvider.credential(
verificationId,
verificationCode
);
// Sets the user variable
await setUser(signInWithCredential(auth, credential).user);
console.log(user);
console.log("phone auth worked with user");
} catch (err) {
console.log(err);
}};
I use the following code to send the verificationCode:
const sendPhoneVCode = async () => {
// The FirebaseRecaptchaVerifierModal ref implements the
// FirebaseAuthApplicationVerifier interface and can be
// passed directly to `verifyPhoneNumber`.
try {
const phoneProvider = new PhoneAuthProvider(auth);
const verificationId = await phoneProvider.verifyPhoneNumber(
phoneNumber,
recaptchaVerifier.current
);
setVerificationId(verificationId);
console.log("Send to phone");
} catch (err) {
console.log(err);
}};
If you input the right verificationCode the function still logs a null user value but then this function sets the right user value afterwards
auth.onAuthStateChanged((foundUser) => {
if (foundUser) {
setUser(foundUser);
console.log("Found user and set it");
}});
Can someone see what my error is?