invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.65k stars 2.21k forks source link

[🐛] Expo APK crashes after confirming OTP #8033

Open SamarthBagga opened 5 hours ago

SamarthBagga commented 5 hours ago

I am using Expo 51 and the latest react native firebase auth libraries. I have built the Expo APK using eas, everything works fine in the emulator device when the app is run using -

npx expo run:android

But when running the apk on an actual device or on the emulator the app crashes when the OTP is verified. I have added the SHA1 and SHA256 keys to firebase and done all the config steps. Here is the code I am using -

import React, { useState, useCallback } from 'react';
import { View, Text, TextInput, TouchableOpacity, Alert } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { themeColors } from '../theme';
import auth from '@react-native-firebase/auth';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';
import i18n from '../i18nConfig';

export default function Login({ navigation }) {
    const [phoneNumber, setPhoneNumber] = useState('');
    const [confirm, setConfirm] = useState(null);
    const [verificationCode, setVerificationCode] = useState('');

    const handleGetOtp = useCallback(async () => {
        try {
            const confirmation = await auth().signInWithPhoneNumber('+91' + phoneNumber);
            setConfirm(confirmation);
            Alert.alert(i18n.t('otpSent'));
        } catch (err) {
            console.log(err);
            Alert.alert(i18n.t('error'), i18n.t('otpSendError'));
        }
    }, [phoneNumber]);

    const handleSubmitOtp = useCallback(async () => {
        try {
            await confirm.confirm(verificationCode);
            Alert.alert(i18n.t('authSuccess'));

            await AsyncStorage.setItem('login', 'true');
            await AsyncStorage.setItem('phone', phoneNumber);
            let userType = "supplier";

            const response = await axios.post(
                'api url',
                { phoneNumber, userType }
            );
            navigation.navigate('Home');
        } catch (err) {
            console.log('signup');
            if (err.response && err.response.status === 404) {
                Alert.alert(i18n.t('userNotRegistered'));
                navigation.navigate('SignUp');
            } else {
                Alert.alert(err)
                Alert.alert(i18n.t('error'), i18n.t('authError'));
            }
        }
    }, [confirm, verificationCode, phoneNumber, navigation]);

    return (
    );
}
mikehardy commented 4 hours ago

Hi there! This issue is missing the required issue template, no indication of concrete version numbers of react-native-firebase or other libraries nor the device it is running on and it's android version, and there is no crash backtrace - difficult to say what could be happening

(something from adb logcat might be useful...)

SamarthBagga commented 14 minutes ago

@mikehardy package.json-

{
  "name": "supp",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "@aws-sdk/client-s3": "^3.650.0",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-firebase/app": "^20.5.0",
    "@react-native-firebase/auth": "^20.5.0",
    "@react-native-picker/picker": "2.7.5",
    "@react-navigation/bottom-tabs": "^6.6.1",
    "@react-navigation/core": "^6.4.17",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "@react-navigation/stack": "^6.4.1",
    "axios": "^1.7.7",
    "expo": "^51.0.34",
    "expo-crypto": "~13.0.2",
    "expo-dev-client": "~4.0.26",
    "expo-image-picker": "~15.0.7",
    "expo-localization": "~15.0.3",
    "expo-location": "~17.0.1",
    "expo-status-bar": "~1.12.1",
    "i18n-js": "^4.4.3",
    "nativewind": "^2.0.11",
    "react": "18.2.0",
    "react-native": "0.74.5",
    "react-native-aws3": "^0.0.9",
    "react-native-feather": "^1.1.2",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-get-random-values": "^1.11.0",
    "react-native-google-places-autocomplete": "^2.5.6",
    "react-native-maps": "1.14.0",
    "react-native-safe-area-context": "4.10.5",
    "react-native-screens": "3.31.1",
    "react-native-svg": "15.2.0",
    "react-native-url-polyfill": "^2.0.0",
    "react-native-vector-icons": "^10.2.0",
    "react-native-webview": "13.8.6",
    "util": "^0.12.5",
    "uuid": "^10.0.0",
    "uuidv4": "^6.2.13",
    "web-streams-polyfill": "^4.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "prettier": "^3.3.3",
    "tailwindcss": "3.3.2"
  },
  "private": true
}

It is a Samsung phone wih anrdoid 14. It is an installed apk i have generated using this command. -

 eas build -p android --profile preview

It is crashing after confirming the OTP. I am not sure how to find the crash backtrace could you help me locate it ? When i try running the adb logcat the terminal starts showing lot of things.

mikehardy commented 9 minutes ago

When i try running the adb logcat the terminal starts showing lot of things.

One of those things will be the crash stack trace