@trudb/tru-common-lib 0.0.701 → 0.0.703
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.
- package/esm2020/lib/components/login/classes/tru-auth-config.mjs +1 -1
- package/esm2020/lib/components/login/classes/tru-auth-jwt-strategy.mjs +1 -14
- package/esm2020/lib/components/login/classes/tru-auth-user-request.mjs +3 -0
- package/esm2020/lib/components/login/services/tru-auth.mjs +16 -16
- package/fesm2015/trudb-tru-common-lib.mjs +17 -26
- package/fesm2015/trudb-tru-common-lib.mjs.map +1 -1
- package/fesm2020/trudb-tru-common-lib.mjs +17 -26
- package/fesm2020/trudb-tru-common-lib.mjs.map +1 -1
- package/lib/components/login/classes/tru-auth-config.d.ts +0 -3
- package/lib/components/login/classes/tru-auth-jwt-strategy.d.ts +0 -5
- package/lib/components/login/classes/tru-auth-user-request.d.ts +3 -0
- package/lib/components/login/services/tru-auth.d.ts +2 -5
- package/package.json +1 -1
|
@@ -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,
|
|
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,42 @@ 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,
|
|
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
|
|
3724
|
+
.pipe(tap(switchMap(data => this.http
|
|
3725
|
+
.post(`${this.baseUrl}${TRU_AUTH_CONFIG.authUrl}/user`, this.createUserRequest(loginRequest.username))
|
|
3726
|
+
.pipe(tap((user) => {
|
|
3720
3727
|
this.auth.doLoginUser(data);
|
|
3728
|
+
this.user.create(user);
|
|
3721
3729
|
this.loggedIn.next(true);
|
|
3722
|
-
}));
|
|
3730
|
+
})))));
|
|
3723
3731
|
}
|
|
3724
3732
|
logout() {
|
|
3725
3733
|
this.doLogoutUser();
|
|
3726
3734
|
}
|
|
3727
|
-
isLoggedIn$() {
|
|
3728
|
-
return this.auth.getCurrentUser().pipe(map(() => true), catchError(() => of(false)));
|
|
3729
|
-
}
|
|
3730
3735
|
get isLoggedIn() {
|
|
3731
3736
|
if (!this.loggedIn.value) {
|
|
3732
3737
|
this.loggedIn.next(this.auth.isLoggedIn());
|
|
3733
3738
|
}
|
|
3734
3739
|
return this.loggedIn.asObservable();
|
|
3735
3740
|
}
|
|
3736
|
-
getCurrentUser$() {
|
|
3737
|
-
return this.auth.getCurrentUser();
|
|
3738
|
-
}
|
|
3739
3741
|
doLogoutAndRedirectToLogin() {
|
|
3740
3742
|
this.doLogoutUser();
|
|
3741
3743
|
this.loggedIn.next(false);
|
|
@@ -3747,14 +3749,14 @@ class TruAuth {
|
|
|
3747
3749
|
this.auth.doLogoutUser();
|
|
3748
3750
|
}
|
|
3749
3751
|
}
|
|
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:
|
|
3752
|
+
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
3753
|
TruAuth.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, providedIn: "root" });
|
|
3752
3754
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImport: i0, type: TruAuth, decorators: [{
|
|
3753
3755
|
type: Injectable,
|
|
3754
3756
|
args: [{
|
|
3755
3757
|
providedIn: "root",
|
|
3756
3758
|
}]
|
|
3757
|
-
}], ctorParameters: function () { return [{ type: i1$6.Router }, { type: i1$3.HttpClient }, { type: TruAuthCache }, { type: TruUser }, { type: TruAppEnvironment }, { type:
|
|
3759
|
+
}], ctorParameters: function () { return [{ type: i1$6.Router }, { type: i1$3.HttpClient }, { type: TruAuthCache }, { type: TruUser }, { type: TruAppEnvironment }, { type: undefined, decorators: [{
|
|
3758
3760
|
type: Inject,
|
|
3759
3761
|
args: [TRU_AUTH_STRATEGY]
|
|
3760
3762
|
}] }]; } });
|
|
@@ -5970,29 +5972,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.1", ngImpor
|
|
|
5970
5972
|
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
5973
|
}], ctorParameters: function () { return [{ type: TruAuth }]; } });
|
|
5972
5974
|
|
|
5973
|
-
const helper = new JwtHelperService();
|
|
5974
5975
|
class TruAuthJwtStrategy {
|
|
5975
5976
|
constructor() {
|
|
5976
5977
|
this.JWT_ACCESS_TOKEN = "ACCESS_TOKEN";
|
|
5977
5978
|
this.JWT_REFRESH_TOKEN = "REFRESH_TOKEN";
|
|
5978
|
-
this.USER_CLAIMS = "USER_CLAIMS";
|
|
5979
5979
|
}
|
|
5980
5980
|
doLoginUser(token) {
|
|
5981
5981
|
localStorage.setItem(this.JWT_ACCESS_TOKEN, JSON.stringify(token.accessToken));
|
|
5982
5982
|
localStorage.setItem(this.JWT_REFRESH_TOKEN, JSON.stringify(token.refreshToken));
|
|
5983
|
-
localStorage.setItem(this.USER_CLAIMS, JSON.stringify(token.userClaims));
|
|
5984
5983
|
}
|
|
5985
5984
|
doLogoutUser() {
|
|
5986
5985
|
localStorage.removeItem(this.JWT_ACCESS_TOKEN);
|
|
5987
5986
|
}
|
|
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
5987
|
isLoggedIn() {
|
|
5997
5988
|
return !!this.getJwtToken();
|
|
5998
5989
|
}
|