【问题标题】:React-Native Firebase AuthenticationReact-Native Firebase 身份验证
【发布时间】:2018-11-18 15:35:48
【问题描述】:

每当我尝试使用 firebase auth 部分运行我的应用程序时,我的 Android 模拟器上都会出现此错误。当我删除它很好。这可能是什么问题?

Objects are not valid as a React child (found: object with keys {typeof, type, key, ref, props, _owner, _store}). If you meant to render a collection of children, use an array instead.
throwOnInvalidObjectType
    ReactNativeRenderer-dev.js:9616:6
reconcileChildFibers

这是我的代码

import React, { Component } from 'react';
import { View } from 'react-native';
import firebase from 'firebase'
import { Header } from './components/common';
import LoginForm from './components/LoginForm';

class App extends Component {
    componentWilMount() {
        firebase.initializeApp({
            apiKey: 'AIzaSyB1eIxhsVkgc9FEv2iwAmbOWVL3ksKBENc',
            authDomain: 'authentication-47519.firebaseapp.com',
            databaseURL: 'https://authentication-47519.firebaseio.com',
            projectId: 'authentication-47519',
            storageBucket: 'authentication-47519.appspot.com',
            messagingSenderId: '823214787474'
        });
    }
    render() {
        return (
            <View>
                <Header headerText="Authentication" />
                <LoginForm />
            </View>

        );
    }
}
export default App;

这可能是什么错误??

【问题讨论】:

  • 您使用哪种身份验证?谷歌或电子邮件和密码?并且它只对模拟器失败
  • 邮箱密码,在真机和模拟器上都不起作用

标签: javascript android firebase react-native firebase-authentication


【解决方案1】:

你需要将这个添加到组件的挂载方法中

componentWillMount(){

    !firebase.apps.length ? firebase.initializeApp({
        apiKey: 'AIzaSyB1eIxhsVkgc9FEv2iwAmbOWVL3ksKBENc',
        authDomain: 'authentication-47519.firebaseapp.com',
        databaseURL: 'https://authentication-47519.firebaseio.com',
        projectId: 'authentication-47519',
        storageBucket: 'authentication-47519.appspot.com',
        messagingSenderId: '823214787474'
    }) : firebase.app();
   .......

添加这样的方法来调用它

onLoginClicked() {
    const { email, password } = this.state;

    firebase.auth().signInWithEmailAndPassword( email, password )
    .then(this.onLoginSuccess.bind(this))
    .catch( () => {
        firebase.auth().createUserWithEmailAndPassword( email, password )
        .then(this.onRegisterSuccess.bind(this))
        .catch( (error) => {
            console.log(error.message);
        });
    });
     console.log(firebase.auth().currentUser.uid);
  }

【讨论】:

    【解决方案2】:

    按照这些步骤帮助我解决了这个问题:

    1. 创建一个 polyfills 文件代码并放入一个名为 polyfills.js 的文件,与 index.js 处于同一级别(我的 react-原生项目)

    2. 代码:

    global.Symbol = require('core-js/es6/symbol');
    require('core-js/fn/symbol/iterator');
    require('core-js/fn/map');
    require('core-js/fn/set');
    require('core-js/fn/array/find');
    
    1. index.js 文件的第一行包含以下代码:
    import './polyfills.js';
    

    现在重新加载应用程序(按 R 两次)。希望它有效!

    Answer Reference

    【讨论】:

      猜你喜欢
      • 2018-03-10
      • 2017-07-12
      • 2016-12-25
      • 2017-06-13
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2021-10-31
      • 2020-10-04
      相关资源
      最近更新 更多