电子邮件/密码身份验证 - 对象而不是功能(firebase和react)



我在我的React应用中具有Firebase设置,并且能够成功地读取数据并将数据读取到数据库中。但是,我正在尝试使用电子邮件和密码设置身份验证,并收到以下错误 -

typeError:对象(...(不是函数

我想念什么?我的代码如下

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();

Ingip.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;

它的 auth.doCreateUserWithEmailAndPassword(email, password)

您需要更改

从'firebase'导入燃料;`

to

从'firebase/ app ';

导入firebase

最新更新