电子邮件/密码验证 - 对象不是功能(Firebase和React)

时间:2018-04-05 01:29:50

标签: reactjs firebase authentication firebase-authentication

我在我的react应用程序中设置了firebase,并且能够成功读取和写入数据库。但是,我正在尝试使用电子邮件和密码设置身份验证,并且收到以下错误 -

TypeError:Object(...)不是函数

我缺少什么?我的代码如下

Firebase.js文件

import firebase from 'firebase';

// Initialize Firebase (removed actual info for confidentiality)
const config = {
    apiKey: "api key here",
    authDomain: "domain here",
    databaseURL: "database url here",
    projectId: "id here",
    storageBucket: "storage bucket here",
    messagingSenderId: "sender Id here "
  };

firebase.initializeApp(config);

export default firebase;

export const database = firebase.database();
export const auth = firebase.auth();

Signup.js文件

import React, { Component } from 'react';
// import ReactDOM from 'react-dom';
import { Router, Link, Route } from 'react-router';
import { database, auth } from '../firebase';

class Signup extends Component {

     constructor(props) {
        super(props)
        // Bind custom methods to object context
        this.signup = this.signup.bind(this)
        // Create firebase database ref
        this.usersRef = database.ref('/users');
        // Set initial state
        this.state = {
          email: '',
          password: '',
          confirmPassword: '',
          firstName: '',
          lastName: '',
        }
    }

    componentDidMount() {
        // Set restaurant state from db
        this.usersRef.on('value', (snapshot) => {
            this.setState({ users: snapshot.val( )});
        });
    }

    // User Signup
    signup(e) {
        e.preventDefault();
        auth().createUserWithEmailAndPassword(this.state.email, this.state.password).catch(function(error) {
            console.log("signed up")
          });
    }

    render() {
        return (
            // Sign up form is here along, signup functon is called upon hitting submit
        )
    }
}

export default Signup;

2 个答案:

答案 0 :(得分:0)

您需要更改

  

从' firebase&#39 ;;

导入firebase

  

从&firebase / 应用';

导入firebase

答案 1 :(得分:0)

这是auth.doCreateUserWithEmailAndPassword(email, password)