Javascript React-Native应用程序显示--signinwithemailandpassword失败:第一个参数“;电子邮件”;必须是有效字符串
当我启动并点击登录按钮时,它显示了上述错误。但它应该说“身份验证错误” 当我成功登录然后注销时,如果我将任何字段设置为空白,则应用程序不会显示错误。 我能解决它吗??下面是Login.js的代码。 请看一下我的密码Javascript React-Native应用程序显示--signinwithemailandpassword失败:第一个参数“;电子邮件”;必须是有效字符串,javascript,reactjs,firebase,authentication,react-native,Javascript,Reactjs,Firebase,Authentication,React Native,当我启动并点击登录按钮时,它显示了上述错误。但它应该说“身份验证错误” 当我成功登录然后注销时,如果我将任何字段设置为空白,则应用程序不会显示错误。 我能解决它吗??下面是Login.js的代码。 请看一下我的密码 import React, {Component} from 'react' ; import {AppRegistry , ActivityIndicator, StyleSheet, Text, View,Image,StatusBar , Touchab
import React, {Component} from 'react' ;
import {AppRegistry , ActivityIndicator, StyleSheet, Text, View,Image,StatusBar , TouchableWithoutFeedback, TextInput, Keyboard, SafeAreaView, TouchableOpacity ,KeyboardAvoidingView } from 'react-native' ;
import firebase from 'firebase' ;
import Button from './Button' ;
import Spinner from './Spinner' ;
import OrderPageNav from './OrderPageNav';
import {StackNavigator} from 'react-navigation';
import Header from './Header' ;
import OrderList from './OrderList';
export default class Login extends Component{
static navigationOptions ={
header:null,
};
state ={ email:'', password:'', error:'', loading:false };
state ={loggedIn:null};
componentWillMount(){
firebase.initializeApp({
apiKey: "AIzaSyD2lZmC5t-eBCZ6PIfdPX654WG8gBphMpU",
authDomain: "dotsp-731e5.firebaseapp.com",
databaseURL: "https://dotsp-731e5.firebaseio.com",
projectId: "dotsp-731e5",
storageBucket: "dotsp-731e5.appspot.com",
messagingSenderId: "732705943561"
});
firebase.auth().onAuthStateChanged((user) =>{
if(user){
this.setState({loggedIn:true});
}else{
this.setState({loggedIn:false});
}
});
}
onButtonPress(){
const {email,password} =this.state;
this.setState({error:'' , loading:true });
firebase.auth().signInWithEmailAndPassword( email, password )
.then(this.onLoginSuccess.bind(this))
.catch(() =>{
firebase.auth().createUserWithEmailAndPassword(email,password)
.then(this.onLoginSuccess.bind(this))
.catch(this.onLoginFailed.bind(this));
});
}
onLoginFailed(){
this.setState({
error:'Authentication Failed',
loading:false
});
}
onLoginSuccess(){
this.setState({
email:'',
password:'',
loading:false,
error:''
});
}
renderButton(){
if(this.state.loading ){
return <Spinner size="large" />;
}else{
return(
<Button onPress={this.onButtonPress.bind(this)} >
Log In
</Button>
)
};
}
renderContent(){
switch(this.state.loggedIn){
case true:
return(
<View style={styles.logocontainer}>
<Image style={styles.logo} source={require('../components/img/logo.png')} />
<TouchableOpacity onPress ={() => this.props.navigation.navigate('OrderList')} >
<Text style={styles.goOrderbtn}>
Go to Order List
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => firebase.auth().signOut() } >
<Text style={styles.logOutBtn} >
Log Out
</Text>
</TouchableOpacity>
</View>
);
case false:
return(
<View style={styles.logocontainer} >
<Image style={styles.logo} source={require('../components/img/logo.png')} />
<Text style={styles.logintitle}> Account Information </Text>
<TextInput
placeholder ='Enter your username'
placeholderTextColor ='#ffffff'
value = {this.state.email}
onChangeText ={email => this.setState({email})}
style={styles.username}
returnKeyType ='next'
underlineColorAndroid='rgba(0,0,0,0)'
autoCorrect ={false}
onSubmitEditing ={() => this.refs.txtpassword.focus()}
/>
<TextInput style={styles.userpass}
placeholder ='Enter your password '
placeholderTextColor ='#ffffff'
value = {this.state.password}
onChangeText ={password => this.setState({password})}
returnKeyType ='go'
secureTextEntry
autoCorrect ={false}
underlineColorAndroid='rgba(0,0,0,0)'
ref ={'txtpassword'}
/>
<Text style={styles.notifytext}>
{this.state.error}
</Text>
{this.renderButton()}
</View>
);
default:
return <Spinner size="large" />;
}
}
render(){
return(
<View style={styles.containerlogin} >
<StatusBar backgroundColor="#602D2F" barStyle="light-content"/>
{this.renderContent()}
</View>
);
}
}
const styles = StyleSheet.create({
goOrderbtn:{
color:'#923438',
alignItems:'center',
backgroundColor:'#F7E3DE',
width:200,
paddingVertical:10,
textAlign:'center'
},
logOutBtn:{
color:'#923438',
alignItems:'center',
backgroundColor:'#F7E3DE',
width:200,
paddingVertical:10,
marginTop: 30 ,
textAlign:'center',
justifyContent:'flex-end'
},
containerlogin : {
flex: 1,
backgroundColor: '#923438',
flexDirection: 'column',
},
logocontainer : {
flex :1,
alignItems: 'center',
justifyContent :'center',
},
logo : {
height : 150 ,
width: 150,
},
logintitle : {
textAlign : 'center',
color :'#ffffff',
fontSize :20,
},
username :{
width : 300,
height : 60,
marginTop : 15 ,
borderWidth : 1 ,
borderColor : '#ffffff',
borderRadius : 8,
color : '#ffffff' ,
fontSize : 16,
padding : 10,
opacity : 0.7,
},
userpass :{
width : 300 ,
height : 60 ,
marginTop : 15 ,
borderWidth : 1 ,
borderColor : '#ffffff',
borderRadius : 8,
color : '#ffffff' ,
fontSize : 16,
padding : 10,
opacity : 0.7,
},
loginbutton :{
paddingVertical : 15 ,
backgroundColor : '#F0E2DA' ,
marginTop : 20 ,
width : 300 ,
},
buttonText : {
color :'#9E494D' ,
alignItems : 'center' ,
textAlign : 'center' ,
borderRadius : 5 ,
fontWeight : 'bold'
},
notifytext : {
color:'#ffffff',
fontSize:20
},
});
import React,{Component}来自'React';
从“react native”导入{AppRegistry、ActivityIndicator、样式表、文本、视图、图像、状态栏、无反馈触摸屏、文本输入、键盘、安全区域视图、触摸屏不透明度、键盘AvoidingView};
从“firebase”导入firebase;
从“./按钮”导入按钮;
从“./Spinner”导入微调器;
从“/OrderPageNav”导入OrderPageNav;
从“react navigation”导入{StackNavigator};
从“./头”导入头;
从“/OrderList”导入订单列表;
导出默认类登录扩展组件{
静态导航选项={
标题:null,
};
状态={电子邮件:“”,密码:“”,错误:“”,加载:false};
状态={loggedIn:null};
组件willmount(){
firebase.initializeApp({
apiKey:“AIzaSyD2lZmC5t-eBCZ6PIfdPX654WG8gBphMpU”,
authDomain:“dotsp-731e5.firebaseapp.com”,
数据库URL:“https://dotsp-731e5.firebaseio.com",
projectId:“dotsp-731e5”,
storageBucket:“dotsp-731e5.appspot.com”,
messagingSenderId:“732705943561”
});
firebase.auth().onAuthStateChanged((用户)=>{
如果(用户){
this.setState({loggedIn:true});
}否则{
this.setState({loggedIn:false});
}
});
}
onButtonPress(){
const{email,password}=this.state;
this.setState({错误:“”,正在加载:true});
firebase.auth().signiWithEmailandPassword(电子邮件,密码)
.then(this.onloginsucess.bind(this))
.catch(()=>{
firebase.auth().createUserWithEmailAndPassword(电子邮件,密码)
.then(this.onloginsucess.bind(this))
.catch(this.onLoginFailed.bind(this));
});
}
onLoginFailed(){
这是我的国家({
错误:'Authentication Failed',
加载:错误
});
}
onloginsucess(){
这是我的国家({
电子邮件:“”,
密码:“”,
加载:false,
错误:“”
});
}
renderButton(){
if(this.state.loading){
返回;
}否则{
返回(
登录
)
};
}
renderContent(){
开关(this.state.loggedIn){
大小写正确:
返回(
this.props.navigation.navigate('OrderList')}>
转到订单列表
firebase.auth().signOut()}>
注销
);
案例错误:
返回(
帐户信息
this.setState({email})}
style={style.username}
returnKeyType='next'
下生色类='rgba(0,0,0,0)'
自动更正={false}
onSubmitEditing={()=>this.refs.txtpassword.focus()}
/>
this.setState({password})}
returnKeyType='go'
secureTextEntry
自动更正={false}
下生色类='rgba(0,0,0,0)'
ref={'txtpassword'}
/>
{this.state.error}
{this.renderButton()}
);
违约:
返回;
}
}
render(){
返回(
{this.renderContent()}
);
}
}
const styles=StyleSheet.create({
goOrderbtn:{
颜色:'#923438',
对齐项目:'中心',
背景颜色:“#F7E3DE”,
宽度:200,
填充垂直:10,
textAlign:“中心”
},
注销BTN:{
颜色:'#923438',
对齐项目:'中心',
背景颜色:“#F7E3DE”,
宽度:200,
填充垂直:10,
玛金托普:30,
textAlign:“中心”,
justifyContent:“柔性端”
},
容器登录:{
弹性:1,
背景颜色:“#923438”,
flexDirection:'列',
},
标识容器:{
弹性:1,
对齐项目:“居中”,
辩护内容:'中心',
},
标志:{
身高:150,
宽度:150,
},
罗金蒂尔:{
textAlign:'中心',
颜色:“#ffffff”,
尺寸:20,