【发布时间】:2015-11-30 20:17:08
【问题描述】:
我正在开发一个 Angular Web 应用程序,该应用程序使用 Firebase 在用户登录或注册时对其进行身份验证。我想限制访问 /dashboard 网址,除非他们已登录。我尝试关注 Firebase 的文档,但我遇到了错误。
我认为我遇到的问题是让我的控制器代码与提供的代码一起工作。我一直收到错误“未知提供者:AuthProvider
任何帮助都会很棒!
这是文档链接:https://www.firebase.com/docs/web/libraries/angular/guide/user-auth.html#section-routers
还有我的代码:
路由器配置
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);
};
});
【问题讨论】:
标签: angularjs authentication firebase ngroute