【问题标题】:TypeError: __WEBPACK_IMPORTED_MODULE_1__firebase__.a.auth(...).createUserWithEmailandPassword is not a function类型错误:__WEBPACK_IMPORTED_MODULE_1__firebase__.a.auth(...).createUserWithEmailandPassword 不是函数
【发布时间】:2020-09-19 12:15:17
【问题描述】:

我是 React 和 Firebase 的初学者,我在尝试从前端注册用户时遇到了这个问题。谁能帮帮我。?我正在使用 Firebase 6.0.2 版。有没有其他方法可以解决这个问题..或者我降级到旧版本的firebase。

注册.js

import React from 'react';
import firebase from '../../firebase';
import {Grid,Form,Segment,Button,Header,Message,Icon} from 'semantic-ui-react';
import {Link} from 'react-router-dom'

class Register extends React.Component{
    state={
        username:'',
        email:'',
        password:'',
        passwordConfirmation:''

    }

    handleChange=event=>{
        this.setState({
            [event.target.name]:event.target.value
        })
    }

    handleSubmit=event=>{
        event.preventDefault();
        firebase
         .auth()
         .createUserWithEmailandPassword(this.state.email,this.state.password)
         .then(createdUser=>{
            console.log(createdUser);
         })
         .catch(err=>{
            console.log(err);

         } )
    }



    render(){
        const {username,email,password,passwordConfirmation}=this.state
        return(
            <Grid textAlign="center" verticalAlign="middle"className="app">
                <Grid.Column style={{maxWidth:450}}>
                    <Header as="h2" icon color="orange" textAlign="center">
                        <Icon name="puzzle piece" color="orange"/>
                            Register for DevChat 
                    </Header>
                    <Form onSubmit={this.handleSubmit}size="large">
                        <Segment stacked>
                            <Form.Input 
                            fluid name="username" 
                            icon="user" iconPosition="left"
                            placeholder="Username" 
                            onChange={this.handleChange} 
                            value={username}
                            type="text"/>

                             <Form.Input fluid name="email" 
                             icon="mail" iconPosition="left"
                            placeholder="Email Address" 
                            onChange={this.handleChange} 
                            value={email}
                            type="email"/>

                            <Form.Input fluid name="password" 
                            icon="lock" iconPosition="left"
                            placeholder="Password" 
                            onChange={this.handleChange} 
                            value={password}
                            type="password"/>

                            <Form.Input fluid name="passwordConfirmation" 
                            icon="repeat" 
                            iconPosition="left"
                            placeholder="Password Confirmation" 
                            onChange={this.handleChange} 
                            value={passwordConfirmation}
                            type="password"/>

                        <Button color="orange" fluid size="large">Submit</Button>
                        
                       
                       
                        </Segment>

                    </Form>
                    <Message> Already a user?<Link to="/login">Login</Link> </Message>
                </Grid.Column>
            </Grid>
        )
    }
}

export default Register

firebase.js

import firebase from 'firebase/app';
import "firebase/auth"
import "firebase/database"
import "firebase/storage"

const firebaseConfig = {
    //credentails
  };
  firebase.initializeApp(firebaseConfig);


  export default firebase;

提前致谢!

【问题讨论】:

  • 您的方法名称中有错字:createUserWithEmailandPassword 应为 createUserWithEmailAndPasswordA 应为大写 And

标签: reactjs firebase react-native redux-firestore


【解决方案1】:

弗兰克斯的评论是正确的,你有一个类型错误

您的句柄提交:

 handleSubmit=event=>{
        event.preventDefault();
        firebase
         .auth()
         .createUserWithEmailandPassword(this.state.email,this.state.password)
         .then(createdUser=>{
            console.log(createdUser);
         })
         .catch(err=>{
            console.log(err);

         } )
    }

您的句柄提交应如下所示或将您的功能更改为此

 handleSubmit=event=>{
        event.preventDefault();
        firebase
  .auth()
  .createUserWithEmailAndPassword(this.state.email,this.state.password) //change in this line
  .then(createdUser=>{
   console.log(createdUser);
    })
  .catch(err=>{
      console.log(err);
         })
    }

如果弗兰克的解决方案对您有用,请忽略这一点(因为这是相同的,但在代码中)

【讨论】:

    猜你喜欢
    • 2018-11-25
    • 2016-09-27
    • 2016-02-26
    • 2013-04-01
    • 2016-03-06
    • 2018-04-28
    • 2019-02-14
    • 2021-10-02
    相关资源
    最近更新 更多