Javascript 试图使Firebase电子邮件/密码身份验证与React Native一起工作
因此,我试图让Firebase电子邮件和密码验证与React Native一起工作 我手动实现了通过插入Javascript 试图使Firebase电子邮件/密码身份验证与React Native一起工作,javascript,firebase,react-native,firebase-authentication,Javascript,Firebase,React Native,Firebase Authentication,因此,我试图让Firebase电子邮件和密码验证与React Native一起工作 我手动实现了通过插入 auth.createUserWithEmailAndPassword('name@email.com','password') 然后连接工作 但是我很难从{this.state.email}&{this.state.password}将正确的格式输入函数。我主要得到:需要2个参数,只有1个或根本没有错误 输入字段的代码设置可能有误。web上的大多数其他示例都使用旧示例 谁有这方面的经验,
auth.createUserWithEmailAndPassword('name@email.com','password')
然后连接工作
但是我很难从{this.state.email}&{this.state.password}将正确的格式输入函数。我主要得到:需要2个参数,只有1个或根本没有错误
输入字段的代码设置可能有误。web上的大多数其他示例都使用旧示例
谁有这方面的经验,可以在这里提供帮助?提前谢谢
额外信息:这会导致语法错误
auth.createUserWithEmailAndPassword(
{this.state.email},
{this.state.password}
)
代码:
“严格使用”;
从“React”导入React,{Component};
进口{
文本,
文本输入,
看法
}从“反应本机”;
从“../components/Button”导入按钮;
从“../components/StatusBar”导入状态栏;
从“./Login”导入登录名;
从“../styles.js”导入样式;
var firebaseConfig={
apiKey:“##”,
authDomain:“##”,
数据库URL:“##”,
storageBucket:“##”,
};
const firebaseApp=firebase.initializeApp(firebaseConfig,'AppB');
firebase.database.enableLogging(true);
const auth=firebaseApp.auth();
类注册扩展了组件{
建造师(道具){
超级(道具);
此.state={
是的,
电子邮件:“”,
密码:“”
};
}
注册(电子邮件、密码){
这是我的国家({
加载:false,
});
auth.createUserWithEmailAndPassword(
“{this.state.email}”,
“{this.state.password}”
)。然后((数据)=>{
if(this.props.onSignupSuccess){
this.props.onSignupSuccess(数据)
}
})
.catch((错误)=>{
var errorCode=error.code;
var errorMessage=error.message;
if(this.props.onLoginError){
this.props.onlogin错误(error.code,error.message)
}
});
这是我的国家({
电子邮件:“”,
密码:“”,
加载:正确
});
}
goToLogin(){
这个是.props.navigator.push({
组件:登录
});
}
render(){
返回(
this.setState({email:text})
值={this.state.email}
占位符={“电子邮件地址”}
/>
this.setState({password:text})}
值={this.state.password}
secureTextEntry={true}
占位符={“密码”}
/>
);
}
}
module.exports=注册;
给你
import-React{
组成部分
}
从"反应",;
进口{
看法
文本,
文本输入,
可触摸不透明度
}
从“反应本机”;
进口{
按钮
}
来自“../common/button”;
从“../../styles”导入样式;
进口{
firebaseApp
}
来自“./身份验证”;
导出类签名扩展组件{
建造师(道具){
超级(道具);
此.state={
电子邮件:“”,//props.email
密码:“”,//props.password
祝酒辞:,
authUser:{}
};
}
componentDidMount(){
firebaseApp.auth().onAuthStateChanged(firebaseUser=>{
if(firebaseUser){
这是我的国家({
authUser:firebaseUser
});
这是我的国家({
toast:`以${this.state.authUser.email}的身份登录`
});
console.log(this.state.authUser);
这个是.props.navigator.push({
屏幕:“主页”
});
}否则{
这是我的国家({
吐司:“注销”
});
}
});
}
render(){
返回(<视图样式={
样式.容器
} >
登录
用户名:
this.setState({
电子邮件:文本
})
}
占位符=“电子邮件”/>
<文本样式={
样式标签
}>密码:
this.setState({password:text})}
占位符=“密码”
/ >
<按钮文本={
“登录”
}
onPress={
()=>this.signIn()
}
/>
忘记密码了?
this.props.navigator.push({screen:'signUp'})}>
注册
<文本样式={
错误
} > {
这个州,烤面包
}
)
}
签名(){
让{
电子邮件、密码
}=本州;
firebaseApp.auth().signInWithEmailAndPassword(电子邮件,密码)
.catch(错误=>{
这是我的国家({
toast:error.message
});
});
}
}
'use strict';
import React, { Component } from 'react';
import {
Text,
TextInput,
View
} from 'react-native';
import Button from '../components/Button';
import StatusBar from '../components/StatusBar';
import Login from './Login';
import styles from '../styles.js';
var firebaseConfig = {
apiKey: "##",
authDomain: "##",
databaseURL: "##",
storageBucket: "##",
};
const firebaseApp = firebase.initializeApp(firebaseConfig, 'AppB');
firebase.database.enableLogging(true);
const auth = firebaseApp.auth();
class Signup extends Component {
constructor(props){
super(props);
this.state = {
loaded: true,
email: '',
password: ''
};
}
signup(email, password){
this.setState({
loaded: false,
});
auth.createUserWithEmailAndPassword(
'{this.state.email}',
'{this.state.password}'
).then((data) => {
if (this.props.onSignupSuccess) {
this.props.onSignupSuccess(data)
}
})
.catch((error) => {
var errorCode = error.code;
var errorMessage = error.message;
if (this.props.onLoginError) {
this.props.onLoginError(error.code, error.message)
}
});
this.setState({
email: '',
password: '',
loaded: true
});
}
goToLogin(){
this.props.navigator.push({
component: Login
});
}
render() {
return (
<View style={styles.container}>
<StatusBar title="Signup" loaded={this.state.loaded} />
<View style={styles.body}>
<TextInput
style={styles.textinput}
onChangeText={(text) => this.setState({email: text})}
value={this.state.email}
placeholder={"Email Address"}
/>
<TextInput
style={styles.textinput}
onChangeText={(text) => this.setState({password: text})}
value={this.state.password}
secureTextEntry={true}
placeholder={"Password"}
/>
<Button
text="Signup"
onpress={this.signup.bind(this)}
button_styles={styles.primary_button}
button_text_styles={styles.primary_button_text} />
<Button
text="Got an Account?"
onpress={this.goToLogin.bind(this)}
button_styles={styles.transparent_button}
button_text_styles={styles.transparent_button_text} />
</View>
</View>
);
}
}
module.exports = Signup;