auth/invalid-value-(email),-starting-an-object-on-a-scalar-field - firebase

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

Related

Adding doc to firebase using react native and encountering many errors with promises/async storage

So im trying to make a todo list app and making the fucntion to add a doc to firebase. However, when i do that expo says the async storage has been deprecated and that there is a unhandled promise rejection
my code in my app:
import React, { useEffect } from 'react';
import {useState} from "react"
import { SafeAreaView, Text, View, Button, TouchableOpacity, Modal, StyleSheet,Pressable, TextInput } from 'react-native';
import { collection, doc, setDoc, query, getDocs, onSnapshot, addDoc, orderBy, limit, Timestamp, where} from "firebase/firestore";
import {db} from "../firebase"
import { signPlsOut } from '../firebase';
import { auth } from '../firebase';
import AsyncStorage from '#react-native-async-storage/async-storage';
export const Dashboard = () => {
const {uid, photoURL, displayName} = auth.currentUser;
const projectsref = collection(db, "projects");
const [modalVisible, setModalVisible] = useState(false);
const [projects, setProjects] = useState([])
const [desc, setDesc] = useState("");
const [title, setTitle] = useState("");
async function handleAddTask () {
try {
await addDoc(projectsref, {
title: title,
desc: desc,
createdAt: Timestamp.fromDate(new Date()),
uid: uid,
})
setTitle("")
setDesc("")
setModalVisible(false)
}
catch(error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
// ADD THIS THROW error
throw error;
}
}
return (
<SafeAreaView>
<View style={{
margin: 20
}}>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert("Modal has been closed.");
setModalVisible(!modalVisible);
}}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Text style={styles.modalText}>Add task:</Text>
<View style={{marginBottom: 20}}>
<TextInput placeholder='title' value={title} onChange={(e) => setTitle(e.target.value)}></TextInput>
<TextInput placeholder='description' value={desc} onChange={(e) => setDesc(e.target.value)}></TextInput>
</View>
<Button title='submit todo' onPress={handleAddTask}></Button>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalVisible(!modalVisible)}
>
<Text style={styles.textStyle}>Cancel</Text>
</Pressable>
</View>
</View>
</Modal>
<Text style={{fontSize: 20, fontWeight: "500"}}>Welcome,</Text>
<Text style={{fontSize: 27, fontWeight: "700"}}>{auth.currentUser.email}</Text>
<View style={{marginTop: 30}}>
<Text style={{fontSize: 40, fontWeight: "700", color: "#0404"}}>Create Task</Text>
<TouchableOpacity>
<View style={{
backgroundColor: "orange",
borderRadius: "20px"
}}>
<Pressable
style={[styles.button, styles.buttonOpen]}
onPress={() => setModalVisible(true)}
>
<Text style={styles.textStyle}>Add task</Text>
</Pressable>
</View>
</TouchableOpacity>
</View>
<Button title="signout" onPress={signPlsOut}></Button>
</View>
</SafeAreaView>
);
};
error:
async sotrage has been extracted and will be removed in a future release, in addition to the unhandled promise rejection error
Are you able to actually add the doc to firebase? Some more context would be helpful in what you're trying to do. Is you code above completely unsucessful and you are getting errors? Or are you simply trying to clear errors.
If you are just trying to get rid of the unhandled promise rejection. I ran into a similar error and I found where in the Firebase app node_module where the call out was being for async storage. For me to get rid of a similar error i did two steps:
First, i installed the new react native async storage module:
npm install #react-native-async-storage/async-storage
Next, i had to update firebase app module, in the following file, to point to the appropriate API within my expo app to point to this new react native async storage module.
./node_modules/#firebase/app/dist/index.rn.cjs.js
I had to adjust this bit of code in this file:
var AsyncStorage = require('#react-native-async-storage/async-storage').AsyncStorage;
firebase.INTERNAL.extendNamespace({
INTERNAL: {
reactNative: {
AsyncStorage: AsyncStorage
}
}
});
The above code previously called to "react" i believe, i just needed to update it to specifically call to "#react-native-async-storage/async-storage". And this solved my problem.

Error: auth/configuration-not .An internal error has occurred

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.

How to pass navigation props in React native in Stack Navigation?

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.

React-Native Passing users email and password to submit button

import FirebaseAPI from '../MyModules/FirebaseAPI';
function submit() {
import FirebaseAPI from '../MyModules/FirebaseAPI';
export default function LinksScreen() {
const [email, onChangeText] = React.useState('Enter Email');
const [password, onChangeText2] = React.useState('Enter Password');
const submit = () => {
FirebaseAPI.createUser(email, password)
}
return (
<KeyboardAvoidingView style={styles.wrapper} behavior="padding">
<View style={styles.scrollViewWrapper}>
<ScrollView style={styles.scrollView}>
<Text style={styles.loginHeader}>Creat an Account </Text>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={text => onChangeText(text)}
value={email}
/>
<TextInput
style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
onChangeText={text => onChangeText2(text)}
value={password}
/>
<TouchableOpacity
style={{marginTop: '5%'}}
onPress= {submit()}>
<View>
<Text>Submit</Text>
</View>
//code from FirebaseAPI.js
import * as firebase from 'firebase'
export const createUser = (email, password) => {
firebase.auth().createUserWithEmailAndPassword(email, password)
.catch((error) => console.log('createUser error: ', error));
}
//etc
my error is
TypeError: undefined is not an object (evaluating '_FirebaseAPI.default.createUser')
I assume its a scoping issue but unsure on how to fix it. Still new at react. Any help would be awesome!
The email and password are not scope of the submit function. You either need to move the submit function inside the component function or pass the values to the function
export default function LinksScreen() {
const [email, onChangeText] = React.useState('Enter Email');
const [password, onChangeText2] = React.useState('Enter Password');
const submit = () => {
FirebaseAPI.createUser(email, password)
}
return (
....
)
OR
<TouchableOpacity
style={{marginTop: '5%'}}
onPress= {() => submit(email, password)}>
<View>
<Text>Submit</Text>
</View>
</TouchableOpacity>
Also where you are importing the FirebaseAPI import as
import * as FirebaseAPI from '../MyModules/FirebaseAPI';

Problem in my react native project firebase module is not recognized

i installed firebase to my project folder and i can see it in node modules folder, but still when i try import firebase from 'firebase' nothing happens
i don't know why i uninstalled it and re installed it
i searched for this problem but with no solution to found it like firebase module does not exist at all
i even restarted my computer
i cannot even intializeApp
i have tried to change my import line too
import React from 'react'
import {
View,
Button,
TextInput,
StyleSheet,
Image,
} from 'react-native'
// import firebase from 'firebase';
import * as firebase from 'firebase'
const firebaseConfig={
apiKey: "AIzaSyCDh998mIGLdyHaE3EK5tRnhLY-I7jiPOY",
authDomain: "shiftorgnaizer.firebaseapp.com",
databaseURL: "https://shiftorgnaizer.firebaseio.com",
projectId: "shiftorgnaizer",
storageBucket: ""
};
export default class SignUp extends React.Component {
state = {
username: '', password: '', email: '', phone_number: ''
}
onChangeText = (key, val) => {
this.setState({ [key]: val })
}
signUp = async () => {
const { username, password, email, phone_number } = this.state
}
render() {
return (
<View style={styles.container}>
<Image source={require('./Images/allImages.jpg')}
style={{width: 150,height: 100}}/>
<TextInput
style={styles.input}
placeholder='Username'
autoCapitalize="none"
placeholderTextColor='white'
onChangeText={val => this.onChangeText('username', val)}
/>
<TextInput
style={styles.input}
placeholder='Password'
secureTextEntry={true}
autoCapitalize="none"
placeholderTextColor='white'
onChangeText={val => this.onChangeText('password', val)}
/>
<TextInput
style={styles.input}
placeholder='Email'
autoCapitalize="none"
placeholderTextColor='white'
onChangeText={val => this.onChangeText('email', val)}
/>
<TextInput
style={styles.input}
placeholder='Phone Number'
autoCapitalize="none"
placeholderTextColor='white'
onChangeText={val => this.onChangeText('phone_number', val)}
/>
<Button
title='Sign Up'
onPress={this.signUp}
/>
</View>
)
}
}
const styles = StyleSheet.create({
input: {
width: 350,
height: 55,
backgroundColor: '#42A5F5',
margin: 10,
padding: 8,
color: 'white',
borderRadius: 14,
fontSize: 18,
fontWeight: '500',
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
})
expected to recognize the module and work with firebase

Categories

Resources