Firebase V3和Ionic社交登录

时间:2016-06-05 16:48:07

标签: angularjs facebook ionic-framework firebase facebook-login

我只是想在Ionic App中创建一个简单的社交登录(例如:google,Facebook,...),并使用Firebase V3作为后端。不幸的是,我在互联网上找到的所有示例和教程似乎都被打破了,并且无法使用新的API v3。

例如,我尝试按照本教程(https://firebase.googleblog.com/2016/01/social-login-with-ionic_77.html?showComment=1465144743780#c7688518627861813273

进行操作

但显然我无法访问以前可用的全局变量Firebase,因此我无法访问app.js的这个片段

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'firebase'])

.constant('FirebaseUrl', 'https://ionicle.firebaseio.com/')

.service('rootRef', ['FirebaseUrl', Firebase])

我收到以下错误

ReferenceError: Can't find variable: Firebase, http://localhost:8103/js/app.js, Line: 12

1 个答案:

答案 0 :(得分:1)

facebookAuth: function () {
    ngFB.login({ scope: 'email' }).then(
        function (response) {
            if (response.status === 'connected') {
                console.log('Facebook login succeeded', response);

                var credential = firebase.auth.FacebookAuthProvider.credential(
                    response.authResponse.accessToken);

                firebase.auth().signInWithCredential(credential).catch(function (error) {
                    // Handle Errors here.
                    var errorCode = error.code;
                    var errorMessage = error.message;
                    // The email of the user's account used.
                    var email = error.email;
                    // The firebase.auth.AuthCredential type that was used.
                    var credential = error.credential;
                    // ...
                });

            } else {
                alert('Facebook login failed');
            }
        });
},

更多详细信息:http://www.clearlyinnovative.com/firebase-3-0-ionic-facebook-login