我在我的应用中使用Facebook登录。当用户单击登录按钮时,Facebook登录弹出窗口会闪烁并登录用户,而不显示弹出窗口并询问用户是否要先登录。总之,一旦用户单击登录按钮,他们就会自动登录。我不确定为什么会这样。身份验证工作正常,Facebook返回authData对象。只是弹出窗口没有按我的意愿工作。
这是控制器:
//============AUTHENTICATION CONTROLLER============
myApp.controller("MyAuthCtrl", ["$scope","$rootScope","$firebaseAuth","$location",
function($scope, $rootScope, $firebaseAuth, $location) {
var ref = new Firebase("myfirebaseUrl");
$scope.authObj = $firebaseAuth(ref);
//============FACEBOOK AUTHENTICATION SCRIPT============
ref.authWithOAuthPopup("facebook", function(error, authData) {
if (error)
{
console.log("Login Failed!", error);
//the function below is necessary to change window location
$scope.$apply(function() {
$location.path('/home');
});
} else
{
$rootScope.currentUser = authData;
//console.log("Authenticated successfully with payload:", authData);
//console.log("User " + authData.uid + " is logged in with " + authData.provider + "name: " + authData.facebook.displayName);
//the function below is necessary to change window location
$scope.$apply(function() {
$location.path('/events');
});
}
});
}
]);
以下是路线:
var myApp = angular.module("myApp", ["ngRoute","firebase"]);
myApp.config(function($routeProvider){
$routeProvider
.when("/events",
{
controller:"eventsController",
templateUrl:"partials/events.html"
})
.when("/home",
{
templateUrl:"partials/home.html"
})
.when("/auth",
{
controller:"MyAuthCtrl",
templateUrl:"partials/home.html"
})
.otherwise(
{
redirectTo:"/home"
})
});