@trudb/tru-common-lib 0.0.697 → 0.0.700

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -73,6 +73,8 @@ import { AgGridModule } from 'ag-grid-angular';
73
73
  import { tap, map, catchError } from 'rxjs/operators';
74
74
  import * as i1$6 from '@angular/router';
75
75
  import { RouterModule } from '@angular/router';
76
+ import * as i6$1 from '@auth0/angular-jwt';
77
+ import { JwtHelperService } from '@auth0/angular-jwt';
76
78
  import * as i1$7 from '@angular/platform-browser';
77
79
  import { BrowserModule } from '@angular/platform-browser';
78
80
  import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@@ -3699,12 +3701,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
3699
3701
  }] });
3700
3702
 
3701
3703
  class TruAuth {
3702
- constructor(router, http, cache, user, appEnvironment, auth) {
3704
+ constructor(router, http, cache, user, appEnvironment, jwtHelperService, auth) {
3703
3705
  this.router = router;
3704
3706
  this.http = http;
3705
3707
  this.cache = cache;
3706
3708
  this.user = user;
3707
3709
  this.appEnvironment = appEnvironment;
3710
+ this.jwtHelperService = jwtHelperService;
3708
3711
  this.auth = auth;
3709
3712
  this.loggedIn = new BehaviorSubject(false);
3710
3713
  this.baseUrl = '';
@@ -3744,14 +3747,14 @@ class TruAuth {
3744
3747
  this.auth.doLogoutUser();
3745
3748
  }
3746
3749
  }
3747
- TruAuth.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, deps: [{ token: i1$6.Router }, { token: i1$3.HttpClient }, { token: TruAuthCache }, { token: TruUser }, { token: TruAppEnvironment }, { token: TRU_AUTH_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
3750
+ TruAuth.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, deps: [{ token: i1$6.Router }, { token: i1$3.HttpClient }, { token: TruAuthCache }, { token: TruUser }, { token: TruAppEnvironment }, { token: i6$1.JwtHelperService }, { token: TRU_AUTH_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
3748
3751
  TruAuth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, providedIn: "root" });
3749
3752
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, decorators: [{
3750
3753
  type: Injectable,
3751
3754
  args: [{
3752
3755
  providedIn: "root",
3753
3756
  }]
3754
- }], ctorParameters: function () { return [{ type: i1$6.Router }, { type: i1$3.HttpClient }, { type: TruAuthCache }, { type: TruUser }, { type: TruAppEnvironment }, { type: undefined, decorators: [{
3757
+ }], ctorParameters: function () { return [{ type: i1$6.Router }, { type: i1$3.HttpClient }, { type: TruAuthCache }, { type: TruUser }, { type: TruAppEnvironment }, { type: i6$1.JwtHelperService }, { type: undefined, decorators: [{
3755
3758
  type: Inject,
3756
3759
  args: [TRU_AUTH_STRATEGY]
3757
3760
  }] }]; } });
@@ -5967,28 +5970,35 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
5967
5970
  args: [{ selector: 'tru-login', template: "<div class=\"login-wrapper\">\r\n <form [formGroup]=\"loginForm\" (ngSubmit)=\"onSubmit()\">\r\n <mat-card class=\"animate-login\">\r\n <mat-card-header>\r\n <mat-card-title> loginFormTitle </mat-card-title>\r\n </mat-card-header>\r\n <mat-card-content>\r\n <mat-form-field>\r\n <mat-label>Username</mat-label>\r\n <input matInput formControlName=\"username\" placeholder=\"Username\">\r\n </mat-form-field>\r\n <mat-form-field>\r\n <mat-label>Password</mat-label>\r\n <input matInput type=\"password\" formControlName=\"password\" placeholder=\"Password\">\r\n </mat-form-field>\r\n <div *ngIf=\"loginError\" class=\"animate-login-error animated rubberBand\">\r\n <p style=\"color: red; font-weight: bold;\"> {{ loginError }}</p>\r\n </div>\r\n </mat-card-content>\r\n <mat-card-actions>\r\n <button mat-raised-button color=\"primary\" type=\"submit\" [disabled]=\"isDisabled()\">Login</button>\r\n </mat-card-actions>\r\n </mat-card>\r\n </form>\r\n</div>\r\n", styles: [".login-container{display:flex;justify-content:center;align-items:center;height:100vh;margin:0;padding:0}.login-input{margin-bottom:20px}.animate-login{display:flex;flex-direction:column;justify-content:center;align-items:center;height:100%;margin-top:50px}.wrapper{display:flex;justify-content:center;align-items:center;height:100vh}mat-card{max-width:300px;width:100%;max-height:300px;padding:20px}.form-group{width:100%;max-width:400px;margin-bottom:20px}.login-wrapper{display:flex;justify-content:center;align-items:center;height:100vh}::ng-deep .login-wrapper .mat-mdc-text-field-wrapper{padding:0 16px!important}\n"] }]
5968
5971
  }], ctorParameters: function () { return [{ type: TruAuth }]; } });
5969
5972
 
5973
+ const helper = new JwtHelperService();
5970
5974
  class TruAuthJwtStrategy {
5971
5975
  constructor() {
5972
- this.JWT_TOKEN = "JWT_TOKEN";
5976
+ this.JWT_ACCESS_TOKEN = "ACCESS_TOKEN";
5977
+ this.JWT_REFRESH_TOKEN = "REFRESH_TOKEN";
5978
+ this.USER_CLAIMS = "USER_CLAIMS";
5973
5979
  }
5974
5980
  doLoginUser(token) {
5975
- localStorage.setItem(this.JWT_TOKEN, JSON.stringify(token));
5981
+ localStorage.setItem(this.JWT_ACCESS_TOKEN, JSON.stringify(token.accessToken));
5982
+ localStorage.setItem(this.JWT_REFRESH_TOKEN, JSON.stringify(token.refreshToken));
5983
+ localStorage.setItem(this.USER_CLAIMS, JSON.stringify(token.userClaims));
5976
5984
  }
5977
5985
  doLogoutUser() {
5978
- localStorage.removeItem(this.JWT_TOKEN);
5986
+ localStorage.removeItem(this.JWT_ACCESS_TOKEN);
5979
5987
  }
5980
5988
  getCurrentUser() {
5981
- //todo check v6 for how this should be done
5982
- return of(JSON.parse(localStorage.getItem(this.JWT_TOKEN))?.user);
5989
+ return of(JSON.parse(helper.decodeToken(localStorage.getItem(this.JWT_ACCESS_TOKEN))));
5990
+ }
5991
+ getUserRoles() {
5992
+ return of(helper.decodeToken(localStorage.getItem(this.JWT_ACCESS_TOKEN)));
5983
5993
  }
5984
5994
  isLoggedIn() {
5985
5995
  return !!this.getJwtToken();
5986
5996
  }
5987
5997
  getJwtToken() {
5988
- return JSON.parse(localStorage.getItem(this.JWT_TOKEN))?.jwt;
5998
+ return JSON.parse(localStorage.getItem(this.JWT_ACCESS_TOKEN));
5989
5999
  }
5990
6000
  getToken() {
5991
- var token = JSON.parse(localStorage.getItem(this.JWT_TOKEN))?.jwt;
6001
+ var token = JSON.parse(localStorage.getItem(this.JWT_ACCESS_TOKEN));
5992
6002
  if (token && token !== "undefined") {
5993
6003
  const encodedPayload = token.split(".")[1];
5994
6004
  const payloadStr = window.atob(encodedPayload);
@@ -5997,7 +6007,7 @@ class TruAuthJwtStrategy {
5997
6007
  var d = new Date();
5998
6008
  var epoch = Math.round(d.getTime() / 1000);
5999
6009
  if (exp < epoch) {
6000
- localStorage.removeItem(this.JWT_TOKEN);
6010
+ localStorage.removeItem(this.JWT_ACCESS_TOKEN);
6001
6011
  return null;
6002
6012
  }
6003
6013
  }