找不到身份提供程序配置 - React Native Firebase Authentication with FacebookAuthProvider

2024-02-08

找不到身份提供商配置

当我尝试使用 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';

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

找不到身份提供程序配置 - React Native Firebase Authentication with FacebookAuthProvider 的相关文章

随机推荐