ngauth v0.0.8
Angular Authorization layer
This module allows you to add authorization layer to your angular project, and to filter pages for "anonymous" and "authenticated" users.
Installation
You can assist the example on AuthExample.js of using ngAuth with ng-facebook module
- Download using one of the following options:
- npm:
npm install ngauth - bower:
bower install ngAuth - git
- npm:
- Add the module to your dependencies and include its scripts
Create your own authentication service by implementing the
AuthBaseabstract:angular.module('myApp', ['ngAuthBase']) .factory('Auth', ['$facebook', 'AuthBaseUI', '$rootScope', function($facebook, AuthBase, $rootScope) { var Auth = angular.extend(AuthBase, {}); return Auth; }]) .run(['Auth', function(Auth) {}]) ;use
AuthBasedependency for regularng-route, andAuthBaseUIforrouter-uiImplement the following methods: 2.1.
setIsLoggedIn()should check if the user is logged-in:true- logged-in userfalse- anonymous usernull- information not available yet(waiting to response)
Usage
Defining routes
- add
anonymous: trueto every route which allowed only for anonymous users - add
authenticated: trueto every route which allowed only for anonymous users
Example:
$stateProvider
.state('login', {
url: '/login',
controller: 'loginCtrl',
anonymous: true,
templateUrl: 'src/app/views/login.html'
})
;Authentication status change handler
You can attach handler for every time the authentication status is changed and ready, by listening to Auth.status:
Example:
$rootScope.$on("Auth.status", function(event, status) {
if(status) {
console.log("Logged In!");
} else {
console.log("Logged out!")
}
});Add login/logout methods to your auth service
It's recommended to add your login/logout method on your auth service.