This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

angular-hb-auth

1.0.12 • Public • Published

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');
    }]);

/angular-hb-auth/

    Package Sidebar

    Install

    npm i angular-hb-auth

    Weekly Downloads

    0

    Version

    1.0.12

    License

    ISC

    Last publish

    Collaborators

    • helderberto
    • helderburato