引发的错误:“未定义不是函数(正在评估'_app.default.auth()')onButtonPress'

时间:2019-01-26 16:17:16

标签: firebase react-native firebase-authentication

我遇到了Firebase问题。我的第一个错误是,我按照this comment的建议将导入更改为import firebase from '@firebase/app'(在import firebase from 'firebase'之前)进行了修复。现在我遇到了另一个问题,我才刚刚开始学习本机反应,所以我穷尽了所有选择。

初始化工作

componentWillMount() {
    firebase.initializeApp({
      apiKey: 'AIzaSy...3LQ7MI...zexagpf9...80',
      authDomain: 'authentication-7...d.firebaseapp.com',
      databaseURL: 'https://authentication-7...d.firebaseio.com',
      projectId: 'authentication-7...d',
      storageBucket: 'authentication-7...d.appspot.com',
      messagingSenderId: '1740...445'
    });
}

然后在我的登录组件中,当按下Login按钮时,

onButtonPress() {
    const { email, password } = this.state;
    firebase
      .auth()
      .signInWithEmailAndPassword(email, password)
      .catch(() => {
        firebase
          .auth()
          .createUserWithEmailAndPassword(email, password)
          .catch(() => {
            this.setState({ error: 'Authentication failed: ' + err });
          });
      });
}

<Button onPress={this.onButtonPress.bind(this)}>Login</Button>

我得到了错误,

undefined is not a function (evaluating '_app.default.auth()')
onButtonPress
    C:\Users\Me\Desktop\react-native_2\auth\src\components\loginForm.js:11:4
proxiedMethod
    C:\Users\Me\Desktop\react-native_2\auth\node_modules\react-proxy\modules\createPrototypeProxy.js:44:35
touchableHandlePress
    C:\Users\Me\Desktop\react-native_2\auth\node_modules\react-native\Libraries\Components\Touchable\TouchableOpacity.js:211:45

也许我正在关注一个过时的教程?

0 个答案:

没有答案