找不到身份提供者配置-使用FacebookAuthProvider

时间:2019-04-04 18:21:21

标签: firebase react-native firebase-authentication facebook-login react-native-fbsdk

未找到身份提供者配置

当我尝试使用FacebookAuthProvider验证到Firebase时出现此错误。我正在使用react-native-fbsdk与react-native进行Facebook身份验证集成。我的目的是使用身份验证令牌登录用户ti firebase并将用户数据记录在firestore中的USERS集合中。

下面是我的代码。感谢您的帮助。

fbAuth(){
        LoginManager.logInWithReadPermissions(['public_profile','email','user_photos']).then(
            (result)=>{
                this.handleCallBack(result),
                function(error){
                    console.log("error in facebook login.");
                }
            }
        );
    }
    handleCallBack(result){
        var _this = this;
        if(result.isCancelled){
            console.log("facebook login cancelled.");
        }else{
            AccessToken.getCurrentAccessToken().then(
                (data) => {
                    const token = data.accessToken;
                    fetch('https://graph.facebook.com/v2.8/me?fields=id,first_name,last_name,gender,birthday&access_token=' + token)
                    .then((response=>response.json()))
                    .then((json)=>{
                        const imageSize = 120;
                        const facebookID = json.id;
                        const fbImage = "https://graph.facebook.com/${facebookID}/picture?height=${imageSize}";
                    })
                    this.authenticate(data.accessToken)
                    .then(result =>{
                        const {uid} =  result;
                        _this.createUser(uid,json,token,fbImage);
                    })
            })
            .catch(error=>{
                    console.log(error);
            })   
        } 
    }
    authenticate = (token) => {
        const provider = firebase.auth.FacebookAuthProvider;
        const credential = provider.credential(token);
        var ret = firebase.auth().signInWithCredential(credential);
        return ret;
    }
    createUser = (uid,userData,token,dp) => {
        const defaults = {
          uid,
          token,
          dp,
          ageRange: [20, 30]
        }
        const db = firebase.firestore();
        db.settings({timestampsInSnapshots:true});
        db.collection('USERS').add({
            ...userData, ...defaults,
            fsTimestamp: firebase.firestore.Timestamp.now()
        })
        .then(()=>{
            console.log("User recorded.");
                //this.clearState();
        })
        .catch((error)=>{console.log(error)});
     }

这是我的进口货

import * as firebase from 'firebase';
import 'firebase/firestore';
import {LoginManager,LoginButton,AccessToken,GraphRequest,GraphRequestManager} from 'react-native-fbsdk';

1 个答案:

答案 0 :(得分:5)

我找到了。问题不在于代码。实际上这是非常基本的东西:) 问题是我没有在Firebase端的“登录提供程序”部分中启用facebook sign-n提供程序。如果遇到相同的问题,则应启用此身份验证方法。

sign-in providers screen