1
我正在使用Firebase在用户登录或注册时对其进行身份验证的Angular Web应用程序。我想限制去/仪表板的网址,除非他们已经登录。我试着跟随Firebase的文档,但我提出了错误。AngularFire(Firebase)和路由器身份验证问题
我想我遇到问题的地方是让我的控制器代码与所提供的代码一起工作。我不断收到错误“未知的提供者:AuthProvider < - Auth < - currentAuth”,所以我现在就拿出他们的控制器代码。
任何帮助将是伟大的!
这里的文档链接:https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html#section-routers
而且我的代码:
ROUTER CONFIG
var app = angular.module('maggsLashes', ['ngRoute', 'ui.calendar', 'firebase']);
app.config(function($routeProvider) {
$routeProvider
.when('/dashboard', {
templateUrl: 'app/templates/dashboardTmpl.html',
controller: 'dashboardCtrl',
resolve: {
// controller will not be loaded until $requireAuth resolves
// Auth refers to our $firebaseAuth wrapper in the example above
"currentAuth": ["Auth", function(Auth) {
// $requireAuth returns a promise so the resolve waits for it to complete
// If the promise is rejected, it will throw a $stateChangeError (see above)
return Auth.$requireAuth();
}]
}
})
仪表板控制器
app.controller('dashboardCtrl', function($scope, $firebaseAuth, $location) {
var ref = new Firebase("https://maggslashes.firebaseio.com/");
var auth = $firebaseAuth(ref);
// app.controller("AccountCtrl", ["currentAuth", function(currentAuth) {
// // currentAuth (provided by resolve) will contain the
// // authenticated user or null if not logged in
// }]);
// console.log(auth);
console.log("Matt is pretty much awesome");
ref.onAuth(function(authData) {
if (authData) {
console.log("User is authenticated w uid:", authData);
}
else {
console.log("client sucks");
}
});
$scope.logOut = function() {
$location.path('/');
$scope.apply();
ref.unauth();
console.log(authData.uid);
};
});