Joe*_*cio 3 javascript facebook firebase react-native firebase-authentication
这是我的代码..非常简单..只是试图允许用户通过facebook进行身份验证,然后将其添加到Firebase系统中!我应该提到我正在使用React Native,我确实读过Firebase库的各个部分不适用于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)
});
});
Run Code Online (Sandbox Code Playgroud)
我真正能想到的唯一原因是Firebase未定义或尚未完成初始化。尽管似乎如此。也许我可以做出某种承诺以确保它已初始化。(有关如何执行此操作的任何想法?)
虽然firebase似乎是初始化的。.但是我仔细阅读了api引用,并无法真正找到.auth.FacebookAuthProvider.credential不存在的任何原因
任何帮助将是巨大的!
我遇到了完全相同的问题,并且有一个适用于我的解决方案,但是我不确定它是否适合您。
我正在通过一个单独的模块在名为FirebaseService.js的文件中实例化我的firebase类。
'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);
Run Code Online (Sandbox Code Playgroud)
然后,我通过导入它在代码中的其他地方使用它:
const { Firebase } = require ('./services/FirebaseService');
Run Code Online (Sandbox Code Playgroud)
在我开始实施Facebook登录之前,这似乎还不错,那时我开始遇到相同的问题。
我必须在尝试登录Facebook的屏幕中导入Firebase。而不是需要自己的服务,我使用了npm模块:
const firebase = require('firebase');
Run Code Online (Sandbox Code Playgroud)
之后,我可以访问FacebookAuthProvider.credential。我真的不确定为什么会这样,我使用模块可能出了点问题
| 归档时间: |
|
| 查看次数: |
3422 次 |
| 最近记录: |