angularjs - Issues with Firebase Auth.$requireAuth() -
so reading on firebase's "user authentication" section find way stop un-authenticated users accessing specific pages (i.e. when they're not logged in)
the solution came across, use snipet of code:
resolve: { // controller not loaded until $requireauth resolves // auth refers our $firebaseauth wrapper in example above 'currentauth': ['auth', function(auth) { // $requireauth returns promise resolve waits complete // if promise rejected, throw $statechangeerror (see above) return auth.$requireauth(); }] }
so after put in , tried access specific page without being logged in, got following error message in console:
error: [$injector:unpr] unknown provider: authprovider <- auth <- currentauth
if try log in after words, unable navigate specific page.
i've been searching around few hours find solution , people said dependency issue not having "ngroute" included in app.js file. have dependency included know that's not issue.
angular .module('app', [ 'nganimate', 'ngcookies', 'ngresource', 'ngroute', 'ngsanitize', 'ngtouch', 'ui.sortable', 'firebase', 'angular-toarrayfilter' ]) .constant('fb', { url: 'https://<url>.firebaseio.com/' }) .factory('firebaseref', function(fb) { return new firebase(fb.url); }) .factory('userauth', function($firebaseauth, firebaseref){ return $firebaseauth(firebaseref); }) .config(function ($routeprovider) { $routeprovider .when('/', { templateurl: 'views/login.html', controller: 'loginctrl', controlleras: 'login_controller' }) .when('/view_resources', { templateurl: 'views/view_resources.html', controller: 'viewresourcesctrl', controlleras: 'view_resources', resolve: { // controller not loaded until $requireauth resolves // auth refers our $firebaseauth wrapper in example above 'currentauth': ['auth', function(auth) { // $requireauth returns promise resolve waits complete // if promise rejected, throw $statechangeerror (see above) return auth.$requireauth(); }] } }) .otherwise({ redirectto: '/' }); });
thanks time.
i think factory
.factory('userauth', function($firebaseauth, firebaseref){ return $firebaseauth(firebaseref); })
should named "auth" follow:
.factory('auth', function($firebaseauth, firebaseref){ return $firebaseauth(firebaseref); })
Comments
Post a Comment