1.0.12 • Published 7 years ago

angular-hb-auth v1.0.12

Weekly downloads
3
License
ISC
Repository
github
Last release
7 years ago

HB Auth Interceptor

This is a simple Angular Auth Token interceptor.

How to Install

$ npm install --save-dev angular-hb-auth
$ bower install angular-hb-auth

How to Use

This module is an simple way to make login token based.

Below is an example of how to use it with angular:

Load module in your app.js, and set the configurations:

  angular
    .module('yourApp', ['hbAuth'])
    .run(['$state', '$rootScope', '$http', 'hbAuth.auth', function ( $state, $rootScope, $http, AuthService) {

      AuthService.setConfig({
        loginRedirect: '/login',
        loggedInRedirect: '/dashboard',
        headerToken: 'Authorization'
      });

      $rootScope.$on("$stateChangeStart", function(event, next, nextParams, fromState) {
        if (!AuthService.isLoggedIn()) {
          if (next.name !== "login") {
            event.preventDefault();
            $state.go('login');
          }
        }
      });
    }]);

NOTE If you don't want to set config, default values are:

  angular
    .module('hbAuth', [])
    .value('hbAuth.config', {
      loginRedirect: '/signin',
      loggedInRedirect: '/menu',
      headerToken: 'Authorization'
    });

Push the authInterceptor to interceptors in your routes.js:

  angular
  .module('yourApp')
    .config(['$httpProvider', function ($httpProvider) {

      $httpProvider.interceptors.push('hbAuth.authInterceptor');
    }]);
1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago