我收到此错误
身份验证失败:TypeError:无法读取属性' displayName' 未定义的。
与此一起,它表明我的fbRef未定义。 我不知道原因。我是Angular和firebase的新手,所以如果有人能帮助我,我将不胜感激。
我的index.html是
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- bower:css -->
<!-- endbower -->
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<link rel="stylesheet" href="css/tab-chat.css">
<link rel="stylesheet" href="css/tab-dash.css">
<script src="https://www.gstatic.com/firebasejs/3.0.4/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.2/firebase-auth.js"></script>
<script>
Initialize Firebase
var config = {
apiKey: "AIzaSyDPCScioFS49tW0rPCjQliUKh5j0Rcw72M",
authDomain: "skinder-858b9.firebaseapp.com",
databaseURL: "https://skinder-858b9.firebaseio.com",
storageBucket: "skinder-858b9.appspot.com",
messagingSenderId: "280323404236"
};
firebase.initializeApp(config);
</script>
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="lib/ng-cordova-oauth/ng-cordova-oauth.js"></script>
<!--rsvp liv-->
<script src="lib/rsvp/rsvp.js"></script>
<!---->
<!-- bower:js -->
<script src="lib/firebase/firebase.js"></script>
<script src="lib/angularfire/dist/angularfire.js"></script>
<script src="lib/lodash/dist/lodash.compat.js"></script>
<script src="lib/angular-google-maps/dist/angular-google-maps.js"></script>
<script src="lib/geofire/dist/geofire.js"></script>
<script src="lib/angular-elastic/elastic.js"></script>
<script src="lib/rxjs/dist/rx.lite.compat.js"></script> </head>
<script src="lib/angular-audio/app/angular.audio.js"></script>
<script src="lib/angular-rx/dist/rx.angular.js"></script>
<script src="lib/parse-js-sdk/lib/parse.js"></script>
<!-- -->
<script src="lib/angular-rx/dist/rx.angular.map"></script>
<!-- endbower -->
<!-- inject:js -->
<script src="js/app.js"></script>
<script src="js/chat/chat_controller.js"></script>
<script src="js/chat/message_service.js"></script>
<script src="js/chat_post/post_controller.js"></script>
<script src="js/chat_post/posts_service.js"></script>
<script src="js/dash_page/dash_controller.js"></script>
<script src="js/dash_page/get_user_service.js"></script>
<script src="js/login/login_controller.js"></script>
<script src="js/logout/logout_controller.js"></script>
<script src="js/map/map_controller.js"></script>
<script src="js/main/main_controller.js"></script>
<!-- endinject -->
<!--for testing-->
<!--todo remove in production-->
<script src="js/services/state-watcher.service.js"></script>
</head>
<body ng-app="skinder">
<!--
The nav bar that will be updated as we navigate between views.
-->
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<!--
The views will be rendered in the <ion-nav-view> directive below
Templates are in the /templates folder (but you could also
have templates inline in this html file if you'd like).
-->
<ion-nav-view></ion-nav-view>
</body>
</html>
我的登录控制器是
/*global Firebase*/
(function(angular) {
'use strict';
var config = {
apiKey: "AIzaSyDPCScioFS49tW0rPCjQliUKh5j0Rcw72M",
authDomain: "skinder-858b9.firebaseapp.com",
databaseURL: "https://skinder-858b9.firebaseio.com",
storageBucket: "skinder-858b9.appspot.com",
messagingSenderId: "280323404236"
};
firebase.initializeApp(config);
angular.module('skinder')
.controller('LoginCtrl', ['$scope', '$firebase', '$firebaseAuth','$firebaseObject', '$window', '$rootScope', '$state', LoginCtrl]);
function LoginCtrl($scope, $firebase, $firebaseAuth,$firebaseObject, $window, $rootScope, $state) {
$scope.login = function () {
var userKey = firebase.auth().currentUser;
var provider = new firebase.auth.FacebookAuthProvider();
var fbRef = firebase.database().ref();
firebase.auth().signInWithPopup(provider)
.then(function(authData) {
console.log("Logged in as:", authData);
$rootScope.userKey = authData.uid;
$state.go('tab.dash');
console.log("value of fbRef is :",fbRef);
console.log("value of userKey is:",userKey);
//todo refactor this to service
//add new user ref to fireabase
fbRef.child('users/'+authData.uid).set({
provider: authData.provider,
user_name: authData.facebook.displayName,
picture: authData.facebook.photoURL
});
return authData;
})
.catch(function(error) {
console.error("Authentication failed:", error);
});
};
//$scope.simpleLogin = $firebaseSimpleLogin(fbRef);
//$scope.errors = [];
//$scope.user = {
// email: '',
// password: ''
//};
//
//$scope.login = function() {
// $scope.errors = [];
//
// if ($scope.user.email === '') {
// $scope.errors.push('Please enter your email');
// }
//
// if ($scope.user.password === '') {
// $scope.errors.push('Please enter your password');
// }
//
// if ($scope.errors.length > 0) {
// return;
// }
//
// var promise = $scope.simpleLogin.$login('password', {
// email: $scope.user.email,
// password: $scope.user.password
// });
//
// promise.then(function(user) {
// console.log(user);
// $rootScope.user = user;
// $window.location.href = '/#/main';
// }, function(error) {
// console.error(error);
// if (error.code === 'INVALID_EMAIL') {
// $scope.errors.push('The email was invalid');
// }
// if (error.code === 'INVALID_PASSWORD') {
// $scope.errors.push('The password was invalid');
// }
// });
//
//};
}
}(window.angular));
我真的很感激这个问题上的任何帮助。谢谢!