![](/img/trans.png)
[英]Firebase authentication with localId / idToken (instead of email / password)
[英]Email/Password Authentication - Object not a function (Firebase and React)
我在我的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;
你需要改变
从“ firebase”导入firebase;
至
从'firebase / app '导入firebase;
其此auth.doCreateUserWithEmailAndPassword(email, password)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.