any Idea why I m getting this issue when I click on sign Up by email and password in React-Native and Firebase ?
[Error: [auth/configuration-not] An internal error has occurred. [ CONFIGURATION_NOT_FOUND ]]
My App.js file
import React,{useEffect,useState} from 'react';
import 'react-native-gesture-handler';
import {
StatusBar,
View,
Text
} from 'react-native';
import {Provider} from 'react-redux';
import {store} from './redux/store';
import Home from './screens/Home';
import Cart from './screens/Cart';
import CartDone from './screens/CartDone';
import Login from './screens/Login';
import Register from './screens/Register';
import {NavigationContainer} from '#react-navigation/native';
import {createDrawerNavigator,DrawerContentScrollView,DrawerItem} from '#react-navigation/drawer';
import Product from './screens/Product';
import {Avatar,Drawer} from 'react-native-paper';
import auth from '#react-native-firebase/auth';
const DrawerNav = createDrawerNavigator();
const App=() => {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
// Handle user state changes
function onAuthStateChanged(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber; // unsubscribe on unmount
}, []);
if (initializing) return null;
if(!user){
return(
<Provider store={store}>
<StatusBar barStyle="white" backgroundColor="red" />
<NavigationContainer>
<DrawerNav.Navigator InitialRoute="Login" drawerContent={(props)=><DrawerContent {...props}/>}>
<DrawerNav.Screen name="Login" component={Login} />
<DrawerNav.Screen name="Register" component={Register} />
</DrawerNav.Navigator>
</NavigationContainer>
</Provider>
);
}
return (
<Provider store={store}>
<StatusBar barStyle="white" backgroundColor="red" />
<NavigationContainer>
<DrawerNav.Navigator InitialRoute="Home" drawerContent={(props)=><DrawerContent {...props}/>}>
<DrawerNav.Screen name="Home" component={Home} />
<DrawerNav.Screen name="Cart" component={Cart} />
<DrawerNav.Screen name="CartDone" component={CartDone} />
<DrawerNav.Screen name="Product" component={Product} />
</DrawerNav.Navigator>
</NavigationContainer>
</Provider>
);
};
function DrawerContent(props){
return(
<DrawerContentScrollView {...props}>
<View style={{flex:1,alignItems:"center"}}>
<Avatar.Image style={{backgroundColor:'white'}} size={130} source={require('./assets/avatar.png')}/>
</View>
<Drawer.Section>
<DrawerItem
label="Home"
icon={()=>(
<Avatar.Icon backgroundColor="white" color="black" size={30} icon="home"/>
)}
onPress={()=>props.navigation.navigate('Home')}
/>
<DrawerItem
label="Cart"
icon={()=>(
<Avatar.Icon backgroundColor="white" color="black" size={30} icon="cart"/>
)}
onPress={()=>props.navigation.navigate('Cart')}
/>
<DrawerItem
label="Login"
icon={()=>(
<Avatar.Icon backgroundColor="white" color="black" size={30} icon="account"/>
)}
onPress={()=>props.navigation.navigate('Login')}
/>
</Drawer.Section>
</DrawerContentScrollView>
);
}
export default App;
my Register.js file :
import React,{useState} from 'react'
import {View,StyleSheet,TouchableOpacity,TextInput} from 'react-native';
import Header from '../components/header';
import {Item,Input,Icon,Label,CheckBox,ListItem,Body,Text} from "native-base";
//react-native-hide-show-password-input
//import auth from '#react-native-firebase/auth';
import { ScrollView } from 'react-native-gesture-handler';
import firestore from '#react-native-firebase/firestore';
export default Register = ({navigation})=>{
return (
<Header screen="Register" component={Main} navigation={navigation} />
)
}
const Main=(props)=>{
const [email,setemail]=useState('');
const [password,setpassword]=useState('');
const [firstName,setfirstName]=useState('');
const [lastName,setLastName]=useState('');
const [secureText,setSecureText]=useState(true);
const [isChecked,setisChecked]=useState(false);
function CreateUser(){
if(email!="" && email!=null && password!="" && password!=null && isChecked==true ){
auth()
.createUserWithEmailAndPassword(email,password)
.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.log("last one",error);
});
}
// adding user to firestore
/*firestore()
.collection('Users')
.add({
name: firstName+" "+lastName,
email : email,
password : password,
})
.then(() => {
console.log('User added!');
})
.catch(err=>console.log(err)); */
}
return (
<ScrollView>
<View style={styles.Container}>
<View style={styles.form}>
<Item rounded style={styles.inputstyle}>
<Input
placeholder="First Name"
value={firstName}
onChangeText={text =>setfirstName(text)}
underlineColor="transparent"
/>
</Item>
<Item rounded style={styles.inputstyle}>
<Input
placeholder="Last Name"
value={lastName}
onChangeText={text =>setLastName(text)}
underlineColor="transparent"
/>
</Item>
<Item rounded style={styles.inputstyle}>
<Input
placeholder="Email"
value={email}
onChangeText={text =>setemail(text)}
underlineColor="transparent"
/>
</Item>
<Item rounded style={styles.inputstyle}>
<Input secureTextEntry={secureText} onChangeText={(text)=>setpassword(text)} placeholder='password'/>
<Icon active onPress={()=>setSecureText(secureText==true ? false : true)} name={secureText==true ? "eye-off" : "eye"} />
</Item>
<View style={styles.termscheckboxContainer}>
<ListItem>
<CheckBox onPress={()=>setisChecked(isChecked==false ? true : false)} checked={isChecked} />
<Text style={{ marginLeft:10 }}>Accept the terms and conditions</Text>
</ListItem>
</View>
<TouchableOpacity
onPress={()=>CreateUser()}
style={styles.submit}>
<Text style={styles.submittxt}>Sign up</Text>
</TouchableOpacity>
<View style={styles.divid}>
<View style={styles.line} />
<Text style={styles.or}>or</Text>
<View style={styles.line} />
</View>
<View style={styles.secondpanel}>
<TouchableOpacity style={styles.facebook}>
<Text style={styles.txtsignwith}>Sign In with Facebook</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.google}>
<Text style={styles.txtsignwith}>Sign In with Google</Text>
</TouchableOpacity>
<View style={styles.signupqs}>
<Text style={styles.signupqstxtA}>Already have an account?</Text>
<TouchableOpacity
onPress={()=>props.navigation.navigate('Login')}
style={styles.signupqsbtn}>
<Text style={styles.signupqstxtB}>Sign In</Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</ScrollView>
)
}
I have followed all instructions in React Native Firebase documentation.
Auth function login verification working .
I have also enabled email and password service from firebase.
thanks.
You got this error because you haven't enabled Authentication mode in FireStore console e.g. Email-Password etc.
Have you checked the project_id in your Android app google-services.json file is the same as the Firebase project for which you enabled Google Sign In Authentication? If that is the case and you have not edited the google-services.json file, you can file a support ticket to Firebase.
the problem was the name of the android project is not the same with the name I gave to it on firebase , please if any one faced the same problem just check the name on google firebase file if it has the same configuration name with the project name on firebase. and check all other configurations that you entred manualy on the firebase website.
Related
This is a hot problem I see a lot of people asking it about it in the last couple of days and its not even registered in Firebase Documentations.
Operating System: OS 11.6.1
React-Native
expo-cli 6.0.5
Firebase #9.2.0
Starting with imports ON the actual
[Prettier Code][1]
[1]: https://i.stack.imgur.com/5UfNQ.png
Initialising Firebase (Back-end)
[Prettier Code][2]
[2]: https://i.stack.imgur.com/UZTUu.png
Initializing Auth, and CreateUserWithEmailAndPassword (Back-end)
[Prettier Code][3]
[3]: https://i.stack.imgur.com/9eZdn.png
Form TextInput and Button
[Prettier Code][FORM]
[FORM]: https://i.stack.imgur.com/5Xom9.png
useState and registering Handler { logger() }
[Prettier Code][5]
[5]: https://i.stack.imgur.com/xHDBd.png
LOGS: Firebase: Error (auth/invalid-value-(email),-starting-an-object-on-a-scalar-field-invalid-value-(password),-starting-an-object-on-a-scalar-field).
import { View, Text, Button, TextInput, KeyboardAvoidingView, Keyboard } from 'react-native'
import React, { useState } from 'react'
import styles from '../../Components/Card/Comments/styles'
import { initFirebase, auth, registerUserEmlPwd } from '../../../firebase'
export default function RegisterScreen({navigation}) {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
function logger (){
initFirebase();
registerUserEmlPwd(auth ,email, password )
console.log(email, password);
}
return (
<KeyboardAvoidingView>
<View
style={{
marginTop: 100,
justfiyContent: 'center',
alignItems: 'center',
}}
>
<Text>Register</Text>
<TextInput
placeholder="Email"
returnKeyType="next"
value={email.value}
onChangeText={(text) => setEmail(text)}
error={!!email.error}
errorText={email.error}
autoCapitalize="none"
autoCompleteType="email"
textContentType="emailAddress"
keyboardType="email-address"
/>
<TextInput
placeholder="Password"
returnKeyType="done"
value={password.value}
onChangeText={(text) => setPassword(text)}
error={!!password.error}
errorText={password.error}
secureTextEntry
/>
<Button title="Register" onPress={logger} />
<Button
title="Go Back"
onPress={() => {
navigation.goBack();
}}
/>
</View>
</KeyboardAvoidingView>
);
}
enter code here
I am trying to make a Login page with Phone Authentication to use React-Native-Firebase sdk and I receive OTP through sms and when I confirm the received OTP ,I got a error that: [Error: [auth/unknown] Cannot create PhoneAuthCredential without either verificationProof, sessionInfo, temporary proof, or enrollment ID.]
I am using-
React:18.0.0
React-Native: 0.69.1
React-Native-Firebase:^15.1.1
My code is-
import React, {useState} from 'react';
import {
View,
Text,
StyleSheet,
Image,
TextInput,
TouchableOpacity,
Alert,
} from 'react-native';
import PhoneInput from 'react-native-phone-number-input';
import auth from '#react-native-firebase/auth';
const Login = () => {
const [PhoneNumber, setPhoneNumber] = useState('');
const [otpInput, setOtpInput] = useState('');
const [confirmData, setConfirmData] = useState('');
const sendOtp = async () => {
try {
const responce = await auth().signInWithPhoneNumber(PhoneNumber);
setConfirmData(responce);
console.log(responce);
Alert.alert('Otp is sent please varify it');
} catch (error) {
console.log(error);
}
}
const submitOtp = async () => {
try {
const responce = await confirmData.confirm(otpInput);
console.log(responce);
Alert.alert('Your Number is verified');
} catch (error) {
console.log(error);
}
}
return (
<View>
<View style={styles.con}>
<Text style={styles.container}>Login Screen</Text>
<Image source={require('../assets/logo.png')} style={styles.image} />
</View>
<View style={styles.inputContainer}>
<Text style={styles.labels}>Phone Number:</Text>
<PhoneInput
style={styles.inputStyle}
defaultValue={PhoneNumber}
defaultCode="DM"
layout="first"
keyboardType="number-pad"
onChangeFormattedText={text => setPhoneNumber(text)}
onChangeText={(value) => setPhoneNumber(value)}
/>
</View>
<View>
<TouchableOpacity
style={styles.buttonStyle}>
<Text style={styles.buttonText}>Verify</Text>
</TouchableOpacity>
</View>
<View style={styles.otpContainer}>
<TextInput
style={styles.otpStyle}
placeholder="Enter OTP"
autoCapitalize="none"
secureTextEntry={true}
onChangeText={(value) => setOtpInput(value)}/>
</View>
<View>
<TouchableOpacity style={styles.continueStyle}>
<Text
style={styles.buttonText}
onPress={() => submitOtp()}>
Continue
</Text>
</TouchableOpacity>
</View>
</View>
);
};
export default Login;
I am trying to use Async Storage in react native expo cli to use login credentials even after closing the app. I am using firebase otp authentication as a mode of login. I am struck here to use the previously used phone number and otp. Below is my code.
This is one screen where user will enter mobile number.
import React, {useState, useRef} from 'react'
import { Alert, View } from 'react-native';
import { NativeBaseProvider, Text, Image, Button, Input } from 'native-base';
import { Pressable } from 'react-native';
import { Col, Row, Grid } from "react-native-easy-grid";
import { LinearGradient } from 'expo-linear-gradient';
import styles from '../styles/styles';
import firebase, {phoneAuthProvider} from '../firebase';
import { FirebaseRecaptchaVerifierModal } from 'expo-firebase-recaptcha';
import AsyncStorage from '#react-native-async-storage/async-storage';
const DummyWelcome = ({ navigation }) => {
const [phoneNumber, setPhoneNumber] = useState("");
const [verificationId, setVerificationId] = useState(null);
const recaptchaVerifier = useRef(null);
const sendVerification = async () => {
try {
await AsyncStorage.setItem('phoneNumber', phoneNumber)
}
catch (erorr) {
console.log(error);
}
console.log('Storing phone Number') ;
phoneAuthProvider
.verifyPhoneNumber(phoneNumber, recaptchaVerifier.current)
.then((id) => {
// console.log('verification:',id);
setVerificationId(id);
navigation.navigate("DumOtp", {verificationId: id})
});
};
return (
<NativeBaseProvider>
<FirebaseRecaptchaVerifierModal
ref={recaptchaVerifier}
firebaseConfig={firebase.app().options} />
<Grid >
<LinearGradient
colors={['#64B278', '#03621B']}
style={styles.linearStyle}/>
<Row size={40}
style={styles.containerRow}>
<Image
source={{uri: 'https://d2j6dbq0eux0bg.cloudfront.net/images/30049435/1646525107.jpg'}}
alt="Subhiksha Logo"
width= {150}
height={150}/>
</Row>
<Row size={5}
style={styles.textStyle}>
<Text
style={styles.welcomeText}>Welcome</Text>
</Row>
<Row size={5}
style={styles.textStyle}>
<View>
<Text style={styles.phoneText}>Enter your phone number to contine</Text>
</View>
</Row>
<Row size={10}
style={styles.justifyCenter}>
<Input
style={styles.inputText}
placeholder="Enter your phone Number"
placeholderTextColor= "white"
onChangeText={text => setPhoneNumber(text)}
maxLength={13}
keyboardType='phone-pad'/>
</Row>
<Row size={20}
style={styles.justifyCenter}>
<Pressable
style={styles.pressableStyle}
onPress={sendVerification}>
{/* onPress = {() => */}
{/* text.length < 10 ? Alert.alert("Invalid Submission", "Please Enter 10 digit Mobile Number to continue") : navigation.navigate("DumOtp")}> */}
<Text
style={styles.pressableTextStyle}>Generate OTP</Text>
</Pressable>
</Row>
</Grid>
</NativeBaseProvider>
)
}
export default DummyWelcome
This is another screen where otp will be auto captured.
import React,{ useState, useEffect, useRef } from 'react'
import { NativeBaseProvider, Image, View, Pressable, Text, Button } from 'native-base'
import { Col, Row, Grid } from "react-native-easy-grid";
import { LinearGradient } from 'expo-linear-gradient';
import OTPInputView from '#twotalltotems/react-native-otp-input'
import Clipboard from '#react-native-community/clipboard'
import styles from '../styles/styles';
import AsyncStorage from '#react-native-async-storage/async-storage';
import firebase from '../firebase';
import { FirebaseRecaptchaVerifierModal } from 'expo-firebase-recaptcha';
const DummyOtp = ({ navigation, route }) => {
const [seconds, setSeconds] = useState(60);
const [code, setCode] = useState('');
// const [verificationId, setVerificationId] = useState(null);
const recaptchaVerifier = useRef(null);
const {verificationId} = route.params;
// console.log(code)
useEffect(() => {
if (seconds > 0) {
setTimeout(() => setSeconds(seconds - 1), 1000);
} else {
setSeconds('OTP Expired!');
}
});
const confirmCode = async () => {
try {
const dataa = await AsyncStorage.getItem('phoneNumber');
if(dataa!== null){
const credential = firebase.auth.PhoneAuthProvider.credential(
verificationId,
code
);
firebase
.auth()
.signInWithCredential(credential)
.then((result) => {
// console.log(result);
navigation.navigate("DumQuestion1");
});
}
}
catch (error) {
console.log(error)
}
}
return (
<NativeBaseProvider>
{/* <FirebaseRecaptchaVerifierModal
ref={recaptchaVerifier}
firebaseConfig={firebase.app().options}/> */}
<Grid >
<LinearGradient
colors={['#64B278', '#03621B']}
style={styles.linearStyle}
/>
<Row size={30}
style={styles.justifyCenter}>
<Image
source={{uri: 'https://d2j6dbq0eux0bg.cloudfront.net/images/30049435/1646525107.jpg'}}
alt="Subhiksha Logo"
width= {150}
height={150}
/>
</Row>
<Row size={5}
style={styles.textStyle}>
<Text
style={styles.welcomeText}>Welcome</Text>
</Row>
<Row size={5}
style={styles.textStyle}>
<View>
<Text style={styles.phoneText}>Enter one time password to contine</Text>
</View>
</Row>
<Row size={10}
style={styles.otpRow}>
<OTPInputView
style={styles.otpStyles}
pinCount={6}
autoFocusOnLoad
codeInputFieldStyle={styles.codeInputFieldStyle}
codeInputHighlightStyle={styles.codeInputHighlightStyle}
onChangeText={text => setCode(text)}
onCodeFilled = {(code => {
setCode(code);
})}
/>
</Row>
<Row size={10}
style={styles.centerContainer}>
<Text style={styles.otpTimerText}>{seconds}</Text>
</Row>
<Row size={10}
style={styles.centerContainer}>
<Text underline style={styles.otpNotRecieved}>Didn't receive OTP?</Text>
<Text style={styles.resendText}> Resend</Text>
</Row>
<Row size={15}
style={{alignItems: 'flex-start', justifyContent: 'center', marginTop: 10}}>
<Pressable
style={styles.pressableStyle}
onPress={confirmCode}>
<Text
style={styles.pressableTextStyle}>Authenticate</Text>
</Pressable>
</Row>
{/* <Row size={15}
style={{alignItems: 'flex-start', justifyContent: 'center', marginTop: 10}}>
<Pressable
style={styles.pressableStyle}
onPress={() => console.log(verificationId)}>
<Text
style={styles.pressableTextStyle}>Login</Text>
</Pressable>
</Row> */}
</Grid>
</NativeBaseProvider>
)
}
export default DummyOtp;
The error I'm facing is "Possible Unhandled Promise Rejection (id: 37)"
class AgentDashBoard extends React.Component{
state={
Couriers: [],
ids:[],
Courier_Location: "",
Courier_Status: ""
}
constructor(props){
super(props);
this.subscriber=
firestore()
.collection("Couriers")
.onSnapshot(docs =>{
let Couriers=[]
let ids=[]
docs.forEach(doc=>{
Couriers.push(doc.data())
ids.push(doc.id)
})
this.setState({Couriers})
this.setState({ids})
})
}
updateshipment= (trackid)=> {
firestore()
.collection("Couriers")
.doc(this.state.ids[trackid])
.update({CurrentLocation: this.state.Courier_Location, CurrentStatus: this.state.Courier_Status})
}
render(){
return(
<ScrollView style={{...}}>
<Text style={{...}}> Couriers for Delivery </Text>
{this.state.Couriers.map((Courier, index) =>
<View
key={index}
style={{...}}
>
<View style={{...}}>
<TextInput
style={{...}}
onChangeText={text=>this.setState({ Courier_Location: text})}
placeholder="Current Location">
{Courier.CurrentLocation}
</TextInput>
<TextInput
style={{...}}
onChangeText={text=>this.setState({Courier_Status: text})}
placeholder="Current Status">
{Courier.CurrentStatus}
</TextInput>
<Icon
name="check"
size={25}
style={{...}}
onPress= {(index)=>
this.updateshipment(index)
}
/>
</View>
</View> )}
</ScrollView>
);
}
}
export default AgentDashBoard
Is there a way to display the CurrentLocation and CurrentStatus in 2 textinputs as I have tried to do and then edit that location and status just for one instance within the same onPress function.
The ids[index] returns the document id correctly but I'm unable to use that what can I do?
I am new to react native and facing some issues with React Navigation version 5.x
App.js file is below
import { NavigationContainer } from "#react-navigation/native";
import { createStackNavigator } from "#react-navigation/stack";
import MyDrawer from "./components/MyDrawer";
import LoginScreen from "./screens/LoginScreen";
import firebase from "firebase";
import { firebaseConfig } from "./config";
firebase.initializeApp(firebaseConfig);
const Stack = createStackNavigator();
export default class App extends React.Component {
state = {
isLoggedIn: false,
};
logOut = () => {
this.setState({ isLoggedIn: false });
firebase.auth().signOut();
};
render() {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
{this.state.isLoggedIn ? (
<>
<Stack.Screen name="Home" component={MyDrawer} />
</>
) : (
<Stack.Screen name="SignIn" component={LoginScreen} />
)}
</Stack.Navigator>
</NavigationContainer>
);
}
}
If the user is logged in to firebase it will navigate to MyDrawer.js. It has a custom drawer and the drawer has a log out button.
MyDrawer.js
import HomeScreen from "../screens/HomeScreen";
import Colors from "../Colors";
import ShareListScreen from "../screens/ShareListScreen";
import Inpiration from "../screens/Inspiration";
const Drawer = createDrawerNavigator();
export default class MyDrawer extends React.Component {
state = {
title: this.props,
};
render() {
return (
<Drawer.Navigator
initialRouteName="Home"
drawerContent={(props) => <CustomDrawerContent {...props} />}
>
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Share List" component={ShareListScreen} />
<Drawer.Screen name="Inspiration" component={Inpiration} />
</Drawer.Navigator>
);
}
}
function CustomDrawerContent(props) {
return (
<DrawerContentScrollView {...props}>
<View >
<ImageBackground source={image} >
<Text>
Bring
<Text>Me</Text>
</Text>
</ImageBackground>
</View>
<DrawerItemList {...props} />
<ImageBackground source={home} >
<Text >Home</Text>
</ImageBackground>
<ImageBackground source={work} >
<Text>Workplace</Text>
</ImageBackground>
<DrawerItem
label="Log out"
onPress={() => {
this.props.logOut;
this.props.navigation.navigate("SignIn");
// Once the button pressed I want the user to sign out from firebase and navigate
to the root and set isLoggedIn state to true in App.js.
}}
/>
</DrawerContentScrollView>
);
}
Once the logout button pressed I want the user to sign out from firebase and navigate to the root and set isLoggedIn state to true in App.js. ( Call the log out function in App.js).
How can I achieve this?
You can use the initialParams to pass the logout function.
<Stack.Screen name="Home" component={MyDrawer} initialParams={{this.logout}}/>
This function can be accessed in MyDrawer class as this.props.routes.params.logout()
And you dont have to navigate to signIn again as the state change happens you render the 'SignIn' so app will show the signin screen automatically.