Expo react-natywna aplikacja z autoryzacją telefonu firebase działa w Internecie, pokazuje błędy w symulatorze ios i wywala bez ostrzeżenia na Android

0

Pytanie

Tworzę aplikację react-native z pomocą expo, mam tylko 2 składniki: ekran powitalny i ekran telefonu. Staram się realizować uwierzytelnianie telefonu firebase, który działa w Internecie, ale na symulatorze iOS pojawia się błąd: Verifier._reset is not a function. (In 'verifier._reset()', 'verifiier._reset' is undefined na Androida jest po prostu wywala, gdy naciskam przycisk "Kontynuuj", która przechodzi do komponentu PhoneLoginScreen. Kody poniżej:

App.js

import React from "react"

import { NavigationContainer } from "@react-navigation/native"
import { createNativeStackNavigator } from "@react-navigation/native-stack"

import WelcomeScreen from "./components/WelcomeScreen"
import PhoneLoginScreen from "./components/auth/PhoneLoginScreen"

const Stack = createNativeStackNavigator()

export default function App() {
    return (
        <NavigationContainer>
            <Stack.Navigator initialRouteName="Welcome">
                <Stack.Screen
                    name="Welcome"
                    component={WelcomeScreen}
                    options={{ headerShown: false }}
                />

                <Stack.Screen
                    name="PhoneLogin"
                    component={PhoneLoginScreen}
                    options={{ headerShown: false }}
                />
            </Stack.Navigator>
        </NavigationContainer>
    )
}

WelcomeScreen.js

import React from "react"
import { Text, View, Button } from "react-native"

export default function WelcomeScreen({ navigation }) {
    return (
        <View
            style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
            <Text>Welcome</Text>
            <Button
                title="Continue"
                onPress={() => navigation.navigate("PhoneLogin")}
            />
        </View>
    )
}

PhoneLoginScreen.js

import React, { useRef, useState } from "react"
import { firebaseApp, auth } from "../../firebase"
import {
    Text,
    View,
    TextInput,
    Button,
    StyleSheet,
    TouchableOpacity,
} from "react-native"

import {
    FirebaseRecaptchaVerifierModal,
    FirebaseRecaptchaBanner,
} from "expo-firebase-recaptcha"

import { PhoneAuthProvider, signInWithCredential } from "firebase/auth"

export default function PhoneLoginScreen() {
    const recaptchaVerifier = useRef(null)
    const [message, showMessage] = useState()
    const [phoneNumber, setPhoneNumber] = useState()
    const [verificationId, setVerificationId] = useState()
    const [verificationCode, setVerificationCode] = useState()

    const firebaseConfig = firebaseApp ? firebaseApp.options : undefined
    const attemptInvisibleVerification = true

    return (
        <View style={styles.center}>
            <FirebaseRecaptchaVerifierModal
                ref={recaptchaVerifier}
                firebaseConfig={firebaseConfig}
                attemptInvisibleVerification={attemptInvisibleVerification}
            />

            <Text style={{ marginTop: 20 }}>Enter phone number</Text>

            <TextInput
                style={{ marginVertical: 10, fontSize: 17 }}
                placeholder="+1 999 999 9999"
                autoFocus
                autoCompleteType="tel"
                keyboardType="phone-pad"
                textContentType="telephoneNumber"
                onChangeText={phoneNumber => setPhoneNumber(phoneNumber)}
            />

            <Button
                title="Send Verification Code"
                disabled={!phoneNumber}
                onPress={async () => {
                    try {
                        const phoneProvider = new PhoneAuthProvider(auth)
                        const verificationId =
                            await phoneProvider.verifyPhoneNumber(
                                phoneNumber,
                                recaptchaVerifier.current
                            )
                        setVerificationId(verificationId)
                        showMessage({
                            text: "Verification code has been sent to your phone.",
                        })
                    } catch (err) {
                        showMessage({
                            text: `Error 111: ${err.message}`,
                            color: "red",
                        })
                    }
                }}
            />
            <Text style={{ marginTop: 20 }}>Enter Verification code</Text>
            <TextInput
                style={{ marginVertical: 10, fontSize: 17 }}
                editable={!!verificationId}
                placeholder="123456"
                onChangeText={setVerificationCode}
            />
            <Button
                title="Confirm Verification Code"
                disabled={!verificationId}
                onPress={async () => {
                    try {
                        const credential = PhoneAuthProvider.credential(
                            verificationId,
                            verificationCode
                        )

                        await signInWithCredential(auth, credential)
                        showMessage({
                            text: "Phone authentication successful 
android expo firebase ios
2021-11-23 22:32:26
2
0

Jest to błąd. Twórcy "expo-firebase-odśwież" jeszcze nie opublikowali poprawka, więc dopóki ten dzień nie nastąpi, sam go poprawić:

Przejdź do sekcji node_modules/expo-firebase-recaptcha, otwórz build folder i znajdź FirebaseRecaptchaVerifierModal.js.

Wewnątrz FirebaseRecaptchaVerifierModal dodaj następującą funkcję w definicji składnika:

_reset = () => {}

Podaję fragment pliku po dodaniu określenia pusty funkcji:

FirebaseRecaptchaVerifierModal.js

[...]
            else {
                this.setState({
                    visible: true,
                    visibleLoaded: false,
                    resolve,
                    reject,
                });
            }
        });
    }
    
    /**
     * Add the following line anywhere inside of the FirebaseRecaptchaVerifierModal component.
     */
    _reset = () => {}

    onVisibleLoad = () => {
        this.setState({
            visibleLoaded: true,
        });
    };
[...]

Uwaga.Trzeba to robić po każdej instalacji yarn/npm lub zmiany w node_modules, dopóki wydawcy nie wyślą aktualizacja.

Błąd: weryfikator._reset-nie jest to funkcja. podczas próby logowania z telefonu za pomocą firebase, react native i Expo

2021-11-27 21:29:37

Nie zadziałało. Nadal jest błąd
Deon Dazy
0

FirebaseRecaptchaVerifierModal Próba niewidzialnej kontroli kończy się niepowodzeniem w emulatorze Android, spójrz na to. Jest mi tak dobrze pomaga.

Dodaję :

<FirebaseRecaptchaVerifierModal ref={recaptchaVerifierRef}
     firebaseConfig={firebaseConfig} androidHardwareAccelerationDisabled
     attemptInvisibleVerification />

Ten wiersz na moim FirebaseRecaptchaVerifierModal to pomoże rozwiązać mój problem.

2021-12-04 10:28:43

W innych językach

Ta strona jest w innych językach

Русский
..................................................................................................................
Italiano
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................