I keep on getting "java.lang.IncompatibleClassChangeError" when I try to use RNFirebase auth method on my react native app - firebase

I keep getting the following error and my app crashes when I try to use the method createUserWithEmailAndPassword or signInWithPhoneNumber from RNFirebase on my react native app. This is currently happening only on the android version of my app.
I did all that was mentioned in the documentation, including enabling Android Device Verification API on my Google Cloud Platform while I was trying to have the signInWithPhoneNumber method work.
I kept on getting the above-mentioned error on Android 7.0 on a Samsung S6 and Huawei Nova 2i.
Below is the code I used:
import { View, Text } from 'react-native'
import React, { useState } from 'react'
import styles from './styles'
import { Button, TextInput } from 'react-native-paper'
import auth from '#react-native-firebase/auth';
function LoginScreen() {
const [emailID, setEmailID] = useState("");
const [password, setPassword] = useState("");
const [confirm, setConfirm] = useState(null);
const [code, setCode] = useState('');
async function loginWithEmail (email, password) {
await auth()
.createUserWithEmailAndPassword('jane.doe#example.com', 'SuperSecretPassword!')
.then(() => {
console.log('User account created & signed in!');
})
.catch(error => {
if (error.code === 'auth/email-already-in-use') {
console.log('That email address is already in use!');
}
if (error.code === 'auth/invalid-email') {
console.log('That email address is invalid!');
}
console.error(error);
});
}
return (
<View style={styles.container}>
<View style={styles.textInputContainer}>
<TextInput mode="outlined"
label='Enter your email'
keyboardType="email-address"
value={emailID}
onChangeText={(e) => setEmailID(e)} />
<TextInput mode="outlined"
label='Enter your password'
secureTextEntry
value={password}
onChangeText={(e) => setPassword(e)} />
</View>
<View style={styles.buttonContainers}>
<Button mode="contained" style={styles.signUpButton} disabled={emailID.length > 5 && password.length > 6 ? false : true} onPress={() => loginWithEmail(emailID, password)}>Login</Button>
</View>
</View>
)
}
export default LoginScreen
Any help in pointing out where I went wrong would be of great help. Thank you

Related

AxiosError network erreur in react native

import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { View, Text } from 'react-native';
const PostsList = () => {
const [posts, setPosts] = useState([]);
useEffect(() => {
axios.defaults.headers.common['Authorization'] = 'mykey';
axios.get('http://myurl')
.then(res => {
setPosts(res.data);
})
.catch(error => console.error(error));
}, []);
return (
<View>
{posts.map(post => (
<Text key={post.id}>{post.title.rendered}</Text>
))}
</View>
);
};
export default PostsList;
I'm asking help because I have a problem with React Native and the WordPress REST API. I am trying to access it with Axios but it returns the following error: ERROR [AxiosError: Network Error]
I am using Expo and testing it on my own Android device (not an emulator). It should be noted that my WordPress is hosted locally and I have tried specifying my IP, but to no avail. Does anyone can help me please ?
Thank you.
I tried to put my own ip and to disable my firewall

how to show reCaptcha in phone authentication firebase react native

When I'm going to authenticate with phone number I get this error
how can I use reCaptcha I can't use safe net Method in phone authentication because my country is not exist when I want to create google cloud account.
this is my code.
please help me and if you have a good doc for solving this problem send me its link
import firebase from '#react-native-firebase/app';
import auth from '#react-native-firebase/auth';
const firebaseConfig = {
apiKey: 'xxxxxxxxxxxx',
authDomain: 'xxxxxxxxxxxxx',
projectId: 'xxxxxxxxxxxxx',
storageBucket: 'xxxxxxxxxxxxxx',
messagingSenderId: 'xxxxxxxxxxxxx',
appId: 'xxxxxxxxxxxxxxx',
measurementId: 'xxxxxxxxxxxxxx',
};
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
export default () => {
return { firebase, auth };
};
const SignUPScreen = ({ navigation }) => {
const { auth } = firebaseSetup();
const [confirm, setConfirm] = useState(null);
const [phoneNumber, setPhoneNumber] = useState('');
const signIn = async () => {
try {
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
setConfirm(confirmation);
navigation.navigate('OTP', { confirm: confirm });
} catch (error) {
alert(error);
}
};
return (
<View style={styles.container}>
<TextInput
style={styles.textInput}
placeholder="Enter your phone number"
keyboardType="phone-pad"
onChangeText={(text) => setPhoneNumber(text)}
/>
<Button title="Sign Up" onPress={() => signIn()} />
</View>
);
};
import { useState } from 'react';
import { Alert, Button, StyleSheet, View } from 'react-native';
import { TextInput } from 'react-native-paper';
const OTP = ({ route }) => {
const { confirm } = route.params;
const [code, setCode] = useState('');
const confirmCode = async () => {
try {
await confirm.confirm(code);
Alert.alert('User sign in SuccessFully');
} catch (error) {
Alert.alert('Invalid code');
}
};
return (
<View style={styles.container}>
<TextInput
style={styles.textInput}
placeholder="Enter the OTP code"
value={code}
onChangeText={(text) => setCode(text)}
/>
<Button title="Confirm Code" onPress={() => confirmCode()} />
</View>
);
};
I found that the problem is due to SHA1.
I had filled in an wrong SHA1 key in the Firebase console.
I change it with correct SHA1 then the error have been gone.

Firebase: The continue URL provided in the request is invalid. (auth/invalid-continue-uri)

I have a resetPassword method which displays the error message
Firebase: The continue URL provided in the request is invalid. (auth/invalid-continue-uri).
I cannot seem to find any related problems on this and none of the tutorials / docs mention a continue-url (I am making a mobile application with react native so adding a url is confusing me). Also my console.log("reset email sent to " + email); shows the correct email address but the email never comes through. Any help is appreciated.
My code:
`
import React, { useState } from 'react'
import { View, TextInput, StyleSheet, Text, TouchableWithoutFeedback, Keyboard, TouchableOpacity } from 'react-native'
import { auth } from '../firebase';
const ForgotPasswordScreen = () => {
const [email, setEmail] = useState('');
const resetPassword = () => {
console.log("reset email sent to " + email);
auth
.sendPasswordResetEmail(auth, email)
.then(() => {
alert("reset email sent to " + email);
})
.catch(function (error) {
console.log(error);
});
};
return (
<TouchableWithoutFeedback onPress={() => {
Keyboard.dismiss();
}}>
<View style={styles.container}>
<Text style={styles.heading}>Forgot your password?</Text>
<Text style={styles.heading}>Enter your email address and we will send you a link to reset your password!</Text>
<View style={styles.inputContainer}>
<TextInput placeholder='Email'
placeholderTextColor="black"
keyboardType='email-address'
value={email}
onChangeText={text => setEmail(text)} style={styles.input} />
</View>
<View style={styles.buttonContainer}>
<TouchableOpacity onPress={resetPassword} style={styles.button} >
<Text style={styles.buttonText}>Send Reset Link To Email</Text>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
)
}
export default ForgotPasswordScreen
`
I found the solution by changing .sendPasswordResetEmail(auth, email) to .sendPasswordResetEmail(email)

React Native Expo onAuthStateChanged fails in APK

I've implemented some basic registration/login functionality using Firebase email/password authentication. Everything works just fine on a simulator and via the Expo Go app however when I use expo build:android and install the apk on my android phone it seems to crash on onAuthStateChanged with no errors. I've tried to catch the error but getting no luck.
I've set it up as follows:
RootNavigator.js:
export default function RootNavigator({ navigation }) {
const [errorMsg, setErrorMsg] = useState();
const { user, setUser } = useContext(AuthenticatedUserContext);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const unsubscribeAuth = auth.onAuthStateChanged(async authenticatedUser => {
try {
await (authenticatedUser ? setUser(authenticatedUser) : setUser(null));
setIsLoading(false);
} catch (error) {
console.log(error);
setErrorMsg(error.message);
setIsLoading(false);
}
});
return unsubscribeAuth;
}, []);
if (isLoading) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<ActivityIndicator size='large' />
<Text style={{ color: 'red' }}>Loading...</Text>
{errorMsg && <Text style={{ color: 'red' }}>{errorMsg}.</Text>}
</View>
);
}
return (
<NavigationContainer>
{user ? <HomeStack /> : <AuthStack />}
</NavigationContainer>
);
}
And on the Login screen I've got a simple function that logs the user in
const auth = Firebase.auth();
const onLogin = async () => {
try {
if (email !== '' && password !== '') {
await auth.signInWithEmailAndPassword(email, password);
}
} catch (error) {
Alert.alert(error.message)
setLoginError(error.message);
navigation.navigate('Home')
}
};
Firebase init config
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
import Constants from 'expo-constants';
// Initialize Firebase
const firebaseConfig = {
apiKey: Constants.manifest.extra.apiKey,
authDomain: Constants.manifest.extra.authDomain,
projectId: Constants.manifest.extra.projectId,
storageBucket: Constants.manifest.extra.storageBucket,
databaseURL: Constants.manifest.extra.databaseURL,
messagingSenderId: Constants.manifest.extra.messagingSenderId,
appId: Constants.manifest.extra.appId
};
let Firebase;
if (firebase.apps.length === 0) {
Firebase = firebase.initializeApp(firebaseConfig);
}
export default Firebase;
The problem is that when using the installed apk on my android I only ever see the Loading section of the RootNavigator - I've not been able to reproduce using the Expo Go app so I can't find the issue

REACT NATIVE + FIREBASE: running app in cellphone throws "Error: signInWithEmailAndPassword failed: First argument "email" must be a valid string."

Im new to react native, currently building a project with firebase to learn the basics. I used expo to create the project.
While running the project with expo in web browser, everything works just fine, but when i run the app with expo on my android device (moto g30) trying to log an user throws this "Error: signInWithEmailAndPassword failed: First argument "email" must be a valid string."
This is the code:
import React from "react";
import { useState } from "react";
import { View, Button, TextInput } from "react-native";
import firebase from "firebase";
const Login = () => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const onSignIn = () => {
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.then((res) => console.log(res))
.catch((err) => console.log(err));
};
return (
<View>
<TextInput
placeholder="email"
required
value={email}
onChange={(e) => setEmail(e.target.value)}
/>
<TextInput
placeholder="password"
required
value={password}
secureTextEntry={true}
onChange={(e) => setPassword(e.target.value)}
/>
<Button title="LOG" onPress={onSignIn} />
</View>
);
};
export default Login;

Resources