Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用react native for mobile app将文本输入数据保存到firebase_Firebase_React Native_Firebase Realtime Database_Firebase Authentication - Fatal编程技术网

使用react native for mobile app将文本输入数据保存到firebase

使用react native for mobile app将文本输入数据保存到firebase,firebase,react-native,firebase-realtime-database,firebase-authentication,Firebase,React Native,Firebase Realtime Database,Firebase Authentication,我尝试将表单值保存到firebase已有一段时间了,但没有成功。如果你能帮忙,请帮忙。这就是我到目前为止所做的 // SignUp.js import firebase from '@firebase/app'; import '@firebase/auth'; import "@firebase/database"; //import {app,db} from '../config'; import { db } from '../config'; import React, { Compo

我尝试将表单值保存到firebase已有一段时间了,但没有成功。如果你能帮忙,请帮忙。这就是我到目前为止所做的

// SignUp.js
import firebase from '@firebase/app';
import '@firebase/auth';
import "@firebase/database";
//import {app,db} from '../config';
import { db } from '../config';
import React, { Component } from 'react';  
import {Alert, StyleSheet, Text, TextInput, View, Button } from 'react-native';

let addItem = (Name,Password,Email) => {  
      db.ref('/items').push({
        name: Name,
        password:Password,
        email:Email
      });
    };

export default class SignUp extends Component {
  state = { 
            email: '', 
            password: '', 
            name:'',
            errorMessage: null 
          };


  handleSubmit = () => {
    addItem(this.state.name,
            this.state.password,
            this.state.email
            );
    alert('Item saved successfully');
  };


render() {
    return (
      <View style={styles.container}>
        <Text>Sign Up</Text>
        {this.state.errorMessage &&
          <Text style={{ color: 'red' }}>
            {this.state.errorMessage}
          </Text>}
        <TextInput
          placeholder="Email"
          autoCapitalize="none"
          style={styles.textInput}
          onChangeText={(email) => this.setState({ email })}
          value={this.state.email}
        />
        <TextInput
          placeholder="Name"
          autoCapitalize="none"
          style={styles.textInput}
          onChangeText={(name) => this.setState({ name })}
          value={this.state.name}
        />
        <TextInput
          secureTextEntry
          placeholder="Password"
          autoCapitalize="none"
          style={styles.textInput}
          onChangeText={(password) => this.setState({ password })}
          value={this.state.password}
        />
        <Button title="Sign Up" onPress={this.handleSubmit} />
        <Button
          title="Already have an account? Login"
          onPress={() => this.props.navigation.navigate('Login')}
        />
      </View>
    )
  }
}
//SignUp.js
从“@firebase/app”导入firebase;
导入'@firebase/auth';
导入“@firebase/database”;
//从“../config”导入{app,db};
从“../config”导入{db};
从“React”导入React,{Component};
从“react native”导入{警报、样式表、文本、文本输入、视图、按钮};
让addItem=(名称、密码、电子邮件)=>{
db.ref('/items').push({
姓名:姓名,,
密码:密码,
电邮:电邮
});
};
导出默认类注册扩展组件{
状态={
电子邮件:“”,
密码:“”,
名称:“”,
错误消息:空
};
handleSubmit=()=>{
addItem(this.state.name,
此.state.password,
这是一封电子邮件
);
警报(“项目已成功保存”);
};
render(){
返回(
注册
{this.state.errorMessage&&
{this.state.errorMessage}
}
this.setState({email})}
值={this.state.email}
/>
this.setState({name})}
值={this.state.name}
/>
this.setState({password})}
值={this.state.password}
/>
this.props.navigation.navigate('Login')}
/>
)
}
}
正在从另一个配置文件调用我的db配置文件。
我已经确认了配置文件和数据库的链接,它正在工作。我已经在另一个addFile.js上使用了它,效果很好。伙计们,如果有人能帮我,我会很感激的。如果有任何关于react native和firebase的材料的建议,我将不胜感激。如果firebase对我来说不是最好的(因为我正在开发一个投资应用程序,我希望获得对其他数据库的建议,如mongodb和关于如何开始的参考资料)

嗨,处理注册的最简单方法是使用firebase身份验证,这允许您使用firebase创建用户并安全地存储所有这些数据。以后您可以随时访问它并将其保存在不同的位置。(确保在firebase身份验证中启用了电子邮件身份验证)

完成此操作后,您可以稍后访问用户数据,如下所示

const user = firebase.auth().currentUser;
var postsRef = ref.child("/items/");
var newPostRef = postsRef.push();
newPostRef.set({
    name: user.displayName,
    email: user.email
});

用户现在将保存您需要的所有数据。请注意,密码将无法访问,因为它是散列的,不应像这样保存在数据库中。这就是firebase限制访问它的原因。我给你们举了一个例子,你们可以在这里找到更多关于push的内容

我想知道如何将其他用户条目存储到firebase,这不仅仅是使用电子邮件和密码注册。假设我想让我的客户注册他们的客户代码和电话号码,我该怎么做呢。或者说,我不想包括otp,它将在登录时发送到他们的手机,我该怎么做。因此,我们的想法是从firebase发送和检索值。非常感谢你回答的第二部分,它为我解决了一个大问题。嗨,如果这是一个有效的答案,请为未来的用户添加V
const user = firebase.auth().currentUser;
var postsRef = ref.child("/items/");
var newPostRef = postsRef.push();
newPostRef.set({
    name: user.displayName,
    email: user.email
});