undefined不是一个对象firebase.auth.FacebookAuthProvider.credential [英] undefined is not an object firebase.auth.FacebookAuthProvider.credential

查看:203
本文介绍了undefined不是一个对象firebase.auth.FacebookAuthProvider.credential的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码..它非常简单..只是试图让用户通过Facebook进行身份验证,然后将其添加到Firebase系统!
我应该提到,我使用的是React Native,我读过Firebase库的各个部分不能与React Native一起工作。 code> const auth = firebase.auth();
const provider = firebase.auth.FacebookAuthProvider;

LoginManager.logInWithReadPermissions(['public_profile'])
.then(loginResult => {

alert(login results)
if (loginResult.isCancelled){
alert('user canceled');
return;
}
AccessToken.getCurrentAccessToken()
.then(accessTokenData => {
const credential = firebase.auth.FacebookAuthProvider.credential(accessTokenData.accessToken);
alert(Credential:+凭证)
return auth.signInWithCredential(凭证);
} )
.then(credData => {
console.log(credData);
alert(CRED data :::+ credData)
alert(firebase)
$ b console.log(err);
alert(ERROR :::+ err)
alert(firebase)
.catch(err =>

});
});

我唯一能想到的是Firebase未定义,或者不能完成初始化..虽然它似乎是..也许我可以把一些承诺,以确保它已经初始化。
(任何想法如何做到这一点?)

虽然firebase似乎initalized ..但我经历了api的参考,并不能真正找到任何原因.auth.FacebookAuthProvider.credential将不存在



任何帮助将是伟大的!

解决方案

我有这个完全相同的问题,我有一个解决方案,但我不知道是否会一样的你。

我通过一个名为 FirebaseService.js
$ b

的文件实例化了我的firebase类。 code> '使用严格'; 
$ b $常量firebase = require('firebase');
const APP_BASE ='https://your-unique-url.firebaseapp.com/'
$ b $常量FIREBASE_CONFIG = {
apiKey:'[super_unique]',
authDomain:'your-unique-url.firebaseapp.com',
databaseURL:APP_BASE,
storageBucket:'your-unique-url.appspot.com',
};

导出常量Firebase = firebase.initializeApp(FIREBASE_CONFIG);

然后我通过导入代码在其他地方使用它:

  const {Firebase} = require('./services/FirebaseService'); 

这似乎没有问题,直到我开始实现Facebook登录时,那就是当我开始同样的问题。



我必须在试图用facebook登录的屏幕上导入Firebase。而不是要求我自己的服务,我用npm模块:

  const firebase = require('firebase'); 

之后,我可以访问FacebookAuthProvider.credential。我真的不知道为什么会这样,模块的使用可能有问题。


Here is my code.. its pretty simple.. just trying to allow a user to authenticate through facebook and then add it to the Firebase system! I should mention that I am using React Native, I did read that various parts of the Firebase library does not work with React Native.

const auth = firebase.auth();
const provider = firebase.auth.FacebookAuthProvider;

LoginManager.logInWithReadPermissions(['public_profile'])
.then(loginResult => {

    alert("login results")
    if (loginResult.isCancelled) {
        alert('user canceled');
        return;
    }
    AccessToken.getCurrentAccessToken()
    .then(accessTokenData => {
        const credential = firebase.auth.FacebookAuthProvider.credential(accessTokenData.accessToken);
        alert("Credential: " + credential )
        return auth.signInWithCredential(credential);
    })
    .then(credData => {
        console.log(credData);
        alert("CRED data:::" + credData)
        alert(firebase)
    })
    .catch(err => {
        console.log(err);
        alert("ERROR:::" + err)
        alert(firebase)

    });
});

The only reasoning I can really think of for this is that Firebase is undefined or it does not finish initializing.. although it seems to be.. maybe I can put in some sort of promise to ensure it has initialized. (Any ideas on how to do that?)

Although firebase seems to be initalized.. but I went through the api reference and can't really find any reason why .auth.FacebookAuthProvider.credential would not exist

Any help would be great!

解决方案

I was having this exact same issue, and I have a solution that worked for me, but I'm not sure if it will be the same for you.

I was instantiating my firebase class through a separate module, in a file called FirebaseService.js

'use-strict';

const firebase = require('firebase');
const APP_BASE = 'https://your-unique-url.firebaseapp.com/'

const FIREBASE_CONFIG = {
    apiKey: '[super_unique]',
    authDomain: 'your-unique-url.firebaseapp.com',
    databaseURL: APP_BASE,
    storageBucket: 'your-unique-url.appspot.com',
};

export const Firebase = firebase.initializeApp(FIREBASE_CONFIG);

I was then using it everywhere else in my code by importing it:

const { Firebase } = require ('./services/FirebaseService');

This appeared to be fine until I got around to implementing facebook login, and that's when I started having the same issue.

I had to import firebase in the screen that was trying to login with facebook. instead of requiring my own service, I used the npm module:

const firebase = require('firebase'); 

After that, I was able to access FacebookAuthProvider.credential. I'm really not sure why this is the case, there may have been something wrong with my use of modules

这篇关于undefined不是一个对象firebase.auth.FacebookAuthProvider.credential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆