@base-fe/authorization
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

BaseFe

@base-fe/authorization

Configure API endpoint: SERVER_URL.

For example: http://192.168.0.2/api => No "/" at the end!

Configure interceptors' callback: 2 callbacks you can use to hanlde the requests in interceptors. One when success, one when failure

interceptErrorHandler(evt) {
  console.log(evt);
},
interceptSuccessHandler(evt) {
  console.log(evt);
},

Configure action's codes for 3 pages: actionPage, modulePage, permissionPage. Below is the default value

const DEFAULT_ACTION_CODES: ActionCodesConfig = {
  actionPage: {
    insert: "INSERT",
    update: "UPDATE",
    delete: "DELETE",
    search: "SEARCH",
    view: "VIEW",
  },
};

Define how to get the user's permission by extending the UserPermissionService class. Example:

import { Injectable } from '@angular/core';
import { UserPermission, UserPermissionService } from '@base-fe/authorization';

@Injectable({providedIn: 'root'})
export class AppUserPermissionService extends UserPermissionService {

  override getUserPermission(): UserPermission[] {
    return [
      {
        "id": 31,
        "title": "Action",
        "code": "ADMIN_ACTION",
        "link": "/pages/sys-config/actions",
        "role": [
          {
            "id": null,
            "codeAction": "INSERT",
            "nameAciton": null,
            "nameModel": null
          },
          {
            "id": null,
            "codeAction": "SEARCH",
            "nameAciton": null,
            "nameModel": null
          },
          {
            "id": null,
            "codeAction": "UPDATE",
            "nameAciton": null,
            "nameModel": null
          }
        ]
      }
    ]
  }
  
}

Use the same way to configure a provider for AccessTokenInjection

import { Injectable } from '@angular/core';
import { TokenProviderService } from '@base-fe/authorization';

@Injectable({providedIn: 'root'})
export class AppTokenProviderService extends TokenProviderService {

  override getToken(): string {
    return localStorage.getItem('Authorization') || '';
  }
   
}

Then use the class as the provider for UserPermissionInjection token in the app.module.ts

providers: [
    { provide: AccessTokenInjection, useClass: AppTokenProviderService },
    { provide: UserPermissionInjection, useClass: AppTokenProviderService },
  ],

Example full configuration

BaseAuthorizationModule.forRoot({
  SERVER_URL: "https://example.com/api",
  interceptErrorHandler(evt) {
    console.log(evt);
  },
  interceptSuccessHandler(evt) {
    console.log(evt);
  },
  ACTION_CODES_PAGES: DEFAULT_ACTION_CODES
}),

Readme

Keywords

none

Package Sidebar

Install

npm i @base-fe/authorization

Weekly Downloads

5

Version

0.0.4

License

none

Unpacked Size

1.33 MB

Total Files

69

Last publish

Collaborators

  • andithang