使用auth()时React Native出现错误

时间:2019-01-14 10:56:24

标签: javascript firebase react-native firebase-authentication

尝试使用Firebase SDK登录时出现错误。 我应该如何处理我的代码?

我的Firebase版本是^ 5.7.3

// LoginFform.js
import React, {Component} from 'react';
import {Text} from 'react-native';
import firebase from '../config/firebase';
import {Button, Card, CardSection, Input, Spinner} from "./common/Common";

class LoginForm extends Component {
state = {email: '', password: '', error: '', loading: false};
 onButtonPress() {
     const {email, password} = this.state;
     this.setState({error: '', loading: true});
     console.log(email);
     console.log(password);
     firebase.auth().signInWithEmailAndPassword(email, password)
         .then(()=>{
             this.onLoginSuccess();
         })
         .catch((err) => {
             firebase.auth().createUserWithEmailAndPassword(email, password)
                 .then(()=>{
                     this.onLoginSuccess();
                 })
                 .catch((err) => {
                     this.onLoginFalied(err);
                 })
         })
  }
}



// firebase.js
import firebase from '@firebase/app'

firebase.initializeApp({
  /* My config */
});
export default firebase;

这是一条错误消息>> _firebase.default.auth不是函数

但是当我在firebase.js中将导入Firebase从'@ firebase / app'更改为从'firebase'导入firebase时,我得到了不同的错误>>不变违规:对象作为React Child无效

1 个答案:

答案 0 :(得分:0)

只需使用“ @ firebase / app”中的导入firebase;然后添加导入'@ firebase / auth'