This is my code from rnfirebase.io.
I receive the SMS code after pressing the sign-in button. But after typing the Verification code, firebase returns me this [auth/session-expired] error.
[Error: [auth/session-expired] The sms code has expired. Please re-send the verification code to try again.]
Also setConfirm(confirmation) does not works. It returns a null again.
How can I solve this problem? Thanks!
import React, { useState } from "react";
import { View, Text, StyleSheet, Button, TextInput } from "react-native";
import auth from "@react-native-firebase/auth";
import colors from "../../config/colors";
// create a component
const UyeOlScreen = () => {
// If null, no SMS has been sent
const [confirm, setConfirm] = useState(null);
const [code, setCode] = useState("");
// Handle the button press
async function signInWithPhoneNumber(phoneNumber) {
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
setConfirm(confirmation);
}
async function confirmCode() {
try {
await confirm.confirm(code);
} catch (error) {
console.log(error);
}
}
if (!confirm) {
return (
<Button
title="Phone Number Sign In"
onPress={() => signInWithPhoneNumber(`+123456789`)}
/>
);
}
return (
<>
<TextInput value={code} onChangeText={(text) => setCode(text)} />
<Button title="Confirm Code" onPress={() => confirmCode()} />
</>
);
};
//make this component available to the app
export default UyeOlScreen; ```