@trudb/tru-common-lib 0.0.701 → 0.0.702

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.
@@ -70,11 +70,9 @@ import * as signalR from '@microsoft/signalr';
70
70
  import moment$1 from 'moment';
71
71
  import * as i8 from 'ag-grid-angular';
72
72
  import { AgGridModule } from 'ag-grid-angular';
73
- import { tap, map, catchError } from 'rxjs/operators';
73
+ import { tap, switchMap, 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';
78
76
  import * as i1$7 from '@angular/platform-browser';
79
77
  import { BrowserModule } from '@angular/platform-browser';
80
78
  import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@@ -3680,6 +3678,9 @@ const TRU_AUTH_CONFIG = {
3680
3678
  };
3681
3679
  const TRU_AUTH_STRATEGY = new InjectionToken("AuthStrategy");
3682
3680
 
3681
+ class TruAuthUserRequest {
3682
+ }
3683
+
3683
3684
  class TruAuthCache {
3684
3685
  constructor() {
3685
3686
  this.prunables = [];
@@ -3701,41 +3702,41 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
3701
3702
  }] });
3702
3703
 
3703
3704
  class TruAuth {
3704
- constructor(router, http, cache, user, appEnvironment, jwtHelperService, auth) {
3705
+ constructor(router, http, cache, user, appEnvironment, auth) {
3705
3706
  this.router = router;
3706
3707
  this.http = http;
3707
3708
  this.cache = cache;
3708
3709
  this.user = user;
3709
3710
  this.appEnvironment = appEnvironment;
3710
- this.jwtHelperService = jwtHelperService;
3711
3711
  this.auth = auth;
3712
3712
  this.loggedIn = new BehaviorSubject(false);
3713
3713
  this.baseUrl = '';
3714
+ this.createUserRequest = (username) => {
3715
+ let truUser = new TruAuthUserRequest();
3716
+ truUser.username = username;
3717
+ return truUser;
3718
+ };
3714
3719
  this.baseUrl = this.appEnvironment.appUri;
3715
3720
  }
3716
3721
  login(loginRequest) {
3717
3722
  return this.http
3718
3723
  .post(`${this.baseUrl}${TRU_AUTH_CONFIG.authUrl}/login`, loginRequest)
3719
- .pipe(tap((data) => {
3720
- this.auth.doLoginUser(data);
3724
+ .pipe(tap((data) => { this.auth.doLoginUser(data); }, switchMap(data => this.http
3725
+ .post(`${this.baseUrl}${TRU_AUTH_CONFIG.authUrl}/user`, this.createUserRequest(loginRequest.username))
3726
+ .pipe(tap((user) => {
3727
+ this.user.create(user);
3721
3728
  this.loggedIn.next(true);
3722
- }));
3729
+ })))));
3723
3730
  }
3724
3731
  logout() {
3725
3732
  this.doLogoutUser();
3726
3733
  }
3727
- isLoggedIn$() {
3728
- return this.auth.getCurrentUser().pipe(map(() => true), catchError(() => of(false)));
3729
- }
3730
3734
  get isLoggedIn() {
3731
3735
  if (!this.loggedIn.value) {
3732
3736
  this.loggedIn.next(this.auth.isLoggedIn());
3733
3737
  }
3734
3738
  return this.loggedIn.asObservable();
3735
3739
  }
3736
- getCurrentUser$() {
3737
- return this.auth.getCurrentUser();
3738
- }
3739
3740
  doLogoutAndRedirectToLogin() {
3740
3741
  this.doLogoutUser();
3741
3742
  this.loggedIn.next(false);
@@ -3747,14 +3748,14 @@ class TruAuth {
3747
3748
  this.auth.doLogoutUser();
3748
3749
  }
3749
3750
  }
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 });
3751
+ 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 });
3751
3752
  TruAuth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, providedIn: "root" });
3752
3753
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, decorators: [{
3753
3754
  type: Injectable,
3754
3755
  args: [{
3755
3756
  providedIn: "root",
3756
3757
  }]
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: [{
3758
+ }], ctorParameters: function () { return [{ type: i1$6.Router }, { type: i1$3.HttpClient }, { type: TruAuthCache }, { type: TruUser }, { type: TruAppEnvironment }, { type: undefined, decorators: [{
3758
3759
  type: Inject,
3759
3760
  args: [TRU_AUTH_STRATEGY]
3760
3761
  }] }]; } });
@@ -5970,29 +5971,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
5970
5971
  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"] }]
5971
5972
  }], ctorParameters: function () { return [{ type: TruAuth }]; } });
5972
5973
 
5973
- const helper = new JwtHelperService();
5974
5974
  class TruAuthJwtStrategy {
5975
5975
  constructor() {
5976
5976
  this.JWT_ACCESS_TOKEN = "ACCESS_TOKEN";
5977
5977
  this.JWT_REFRESH_TOKEN = "REFRESH_TOKEN";
5978
- this.USER_CLAIMS = "USER_CLAIMS";
5979
5978
  }
5980
5979
  doLoginUser(token) {
5981
5980
  localStorage.setItem(this.JWT_ACCESS_TOKEN, JSON.stringify(token.accessToken));
5982
5981
  localStorage.setItem(this.JWT_REFRESH_TOKEN, JSON.stringify(token.refreshToken));
5983
- localStorage.setItem(this.USER_CLAIMS, JSON.stringify(token.userClaims));
5984
5982
  }
5985
5983
  doLogoutUser() {
5986
5984
  localStorage.removeItem(this.JWT_ACCESS_TOKEN);
5987
5985
  }
5988
- getCurrentUser() {
5989
- let token = helper.decodeToken(localStorage.getItem(this.JWT_ACCESS_TOKEN));
5990
- return of(JSON.parse(helper.decodeToken(localStorage.getItem(this.JWT_ACCESS_TOKEN))));
5991
- }
5992
- getUserRoles() {
5993
- let token = helper.decodeToken(localStorage.getItem(this.JWT_ACCESS_TOKEN));
5994
- return of(token);
5995
- }
5996
5986
  isLoggedIn() {
5997
5987
  return !!this.getJwtToken();
5998
5988
  }