Sanji Auth UI

1.4.0 · abandoned · verified Wed Apr 22

Sanji Auth UI is a core component of the Sanji UI framework, specifically designed for seamless integration within AngularJS 1.x applications. It provides robust authentication and authorization services, leveraging JSON Web Tokens (JWT) for secure user identification and session management. The package includes an `auth` service for handling login requests and a `session` service for storing and retrieving authenticated user data. Its current stable version is `1.4.0`, released in September 2018, indicating an infrequent and likely discontinued release cadence. A key differentiator is its tight coupling with the AngularJS 1.x ecosystem (specifically versions 1.5.0 to 1.6.x), making it unsuitable for modern Angular or other contemporary frontend frameworks. It also relies on specific versions of `angular-http-auth`, `angular-storage`, and `sanji-rest-ui` as peer dependencies.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to include the `sanji.auth` AngularJS module, inject the `auth` and `session` services into a controller, perform a user login with credential handling, and configure the `authProvider` and `sessionProvider`.

angular.module('webapp', ['sanji.auth'])
  .controller('AppController', ['$http', 'auth', 'session', function($http, auth, session) {
    this.credentials = { username: '', password: '' };
    this.login = (credentials) => {
      // Authenticate a user
      auth.login('/auth/local', credentials)
      .then((data) => {
        // Return token data
        return $http.get('/users/me');
      })
      .then((res) => {
        // Return authenticated user data and save in session service
        session.setUserData(res.data);
        console.log('User logged in:', session.getUserData());
      })
      .catch((error) => {
        console.error('Login failed:', error);
      });
    };
  }]);

// Example of configuring authProvider
angular.module('webapp').config(['authProvider', function(authProvider) {
  authProvider.configure({
    roles: {
      admin: 'admin',
      guest: 'guest'
    }
  });
}]);

// Example of configuring sessionProvider
angular.module('webapp').config(['sessionProvider', function(sessionProvider) {
  sessionProvider.configure({
    tokenHeader: 'Authorization',
    tokenKey: 'jwt_token'
  });
}]);

view raw JSON →