使用Expo进行React Native(在线)

时间:2019-05-11 13:23:12

标签: javascript firebase react-native firebase-authentication

我是React Native的新手,与在线博览会小吃一起使用。 我已经使用firebase制作了登录和注册页面,每当我单击注册按钮时,都会出现错误“ undefined不是一个对象(正在评估'e.stack.replace')”。 另外,它不会将这些值推送到数据库中,出于隐私目的,我在删除键和链接的同时链接了数据库配置代码。 一切似乎都很好并且可以运行,但是每当我输入值并单击未定义的注册按钮时,就不会出现对象错误(评估“ e.stack.replace”)。

//This is pushing fields into firebase
import {db} from '../config/db';
export const addUser =  (prop) => {
    db.database().ref('/custsocietiesforum').push({
        custsocietiesforum:prop,
    });
};
export const signup = (username,email,pass) => {


    try {
          console.log(pass);
         db.auth()
            .createUserWithEmailAndPassword(email,pass).then((authData) => {
                    console.log("User created successfully with payload-", authData);

                    //Write code to use authData to add to Users
                }).catch((_error) => {
                    console.log("Login Failed!", _error);
                    alert("Unexpected Error");
                });
           // nav.navigate('HomePageScreen');
        console.log("Account created");

        // Navigate to the Home page, the user is auto logged in

    } catch (error) {
        console.log(error);

    }
};
//This is signup page code linked with upper code
  constructor(props) {
    super(props);
    this.state = {

             username: '',
             email:'',
        password: '',

        errorMessage:'',
    }
    this.handleSubmit = this.handleSubmit.bind(this);
  }


      handleSubmit()
 {
   signup(this.state.username,this.state.email,this.state.password);
 }
//This is my DB configuration
import * as firebase from 'firebase'; 

const firebaseConfig = {
   apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: ""
    //appId: ""
};


export const db= !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();

0 个答案:

没有答案