可能未处理的承诺拒绝(id:0)

时间:2017-09-29 14:48:40

标签: android firebase react-native firebase-realtime-database firebase-authentication

我在黄色方框中看到了这个:

可能的未处理承诺拒绝(ID:0): ReferenceError:未定义firebase ReferenceError:未定义firebase

我该如何解决这个问题。

这是我的代码:

    import React, {Component} from 'react';
    import {
      Text,
      View,
      StyleSheet,
      TouchableOpacity,
    } from 'react-native';

    import FBSDK, { LoginManager, AccessToken } from 'react-native-fbsdk';

    import { firebaseRef } from '/home/mayura/AndroidProject/NiceTry/app/services/Firebase.js';
    import _ from 'lodash'
    import Firebase from 'firebase'

    export default class Facebook extends Component{
        _fbAuth(){
            LoginManager.logInWithReadPermissions(['public_profile','email']).then(function(result){
                if(result.isCancelled){
                    console.log('Login was cancelled');
                } else {
                    AccessToken.getCurrentAccessToken().then((AccessTokenData) => {
                        const credential = firebase.auth.FacebookAuthProvider.credential(AccessTokenData.accessToken)
                        firebase.auth().signInWithCredential(credential).then((result) =>{
                            // promise succesful
                             console.log(error.code);
                             console.log(error.message);
                        },(error) => {
                            //promise rejected


                      console.log(error);
                    })
                },(error => {
                    console.log('Some error occured: ' + error);
                }))
            } 
        },function(error){
            console.log('An error occurred: ' + error);

        })

    }

    render(){
    return(
        <View style = {styles.container}>
            <TouchableOpacity onPress={this._fbAuth}>
                <Text>Login with Facebook</Text>
            </TouchableOpacity>

        </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

1 个答案:

答案 0 :(得分:1)

它说firebase is not defined。检查您是否已正确安装并将firebase lib导入组件

希望有所帮助