【问题标题】:React Native has an error when use auth()React Native 使用 auth() 时出错
【发布时间】:2019-06-08 08:39:07
【问题描述】:

我在尝试使用 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 中将 import firebase from '@firebase/app' 更改为 import firebase from 'firebase' 我得到了不同的错误 >> Invariant Violation:Objects are not valid as a React Child

【问题讨论】:

  • 你不应该使用react-native-firebase吗?

标签: javascript firebase react-native firebase-authentication


【解决方案1】:

只需使用 import firebase from '@firebase/app';然后添加 import '@firebase/auth'

【讨论】:

    猜你喜欢
    • 2019-11-20
    • 1970-01-01
    • 2018-03-05
    • 2018-04-19
    • 1970-01-01
    • 2017-10-27
    • 2021-01-03
    • 1970-01-01
    • 2020-07-27
    相关资源
    最近更新 更多