@brggroup/share-lib 0.1.0 → 0.1.1
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.
|
@@ -4,7 +4,7 @@ import * as i1$4 from '@angular/router';
|
|
|
4
4
|
import { Router, ActivatedRoute, NavigationEnd, RouterLink, RouterOutlet } from '@angular/router';
|
|
5
5
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
6
6
|
import * as i3 from '@ngx-translate/core';
|
|
7
|
-
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
|
7
|
+
import { TranslateService, TranslatePipe, TranslateModule } from '@ngx-translate/core';
|
|
8
8
|
import { firstValueFrom, fromEvent, startWith, map, BehaviorSubject, of, catchError, throwError, finalize, from, switchMap as switchMap$1, take, filter, Subject, takeUntil as takeUntil$1 } from 'rxjs';
|
|
9
9
|
import { NzNotificationService } from 'ng-zorro-antd/notification';
|
|
10
10
|
import * as i1 from 'ng-zorro-antd/modal';
|
|
@@ -803,6 +803,7 @@ function authInterceptor(req, next) {
|
|
|
803
803
|
const router = inject(Router);
|
|
804
804
|
const loadingService = inject(LoadingService);
|
|
805
805
|
const authService = inject(AuthService);
|
|
806
|
+
const translate = inject(TranslatePipe);
|
|
806
807
|
const authToken = TokenStorage.getToken();
|
|
807
808
|
const noLoadingMark = req.headers.get('No-Loading-Mark');
|
|
808
809
|
if (noLoadingMark !== '1')
|
|
@@ -822,7 +823,7 @@ function authInterceptor(req, next) {
|
|
|
822
823
|
}
|
|
823
824
|
return next(req).pipe(catchError((error) => {
|
|
824
825
|
if (error.status === 401) {
|
|
825
|
-
return handle401(req, next, router, authService);
|
|
826
|
+
return handle401(req, next, router, authService, translate);
|
|
826
827
|
}
|
|
827
828
|
return throwError(() => error);
|
|
828
829
|
}), finalize(() => {
|
|
@@ -833,7 +834,7 @@ function authInterceptor(req, next) {
|
|
|
833
834
|
//
|
|
834
835
|
// ⭐ REFRESH TOKEN HANDLER
|
|
835
836
|
//
|
|
836
|
-
function handle401(req, next, router, authService) {
|
|
837
|
+
function handle401(req, next, router, authService, translate) {
|
|
837
838
|
if (!isRefreshing) {
|
|
838
839
|
isRefreshing = true;
|
|
839
840
|
refreshTokenSubject.next(null);
|
|
@@ -848,8 +849,8 @@ function handle401(req, next, router, authService) {
|
|
|
848
849
|
router.navigate(['/login'], {
|
|
849
850
|
queryParams: { returnUrl: initialReturnUrl || '/' },
|
|
850
851
|
});
|
|
851
|
-
refreshTokenSubject.error('Refresh token failed');
|
|
852
|
-
return throwError(() => new Error('Refresh token failed'));
|
|
852
|
+
refreshTokenSubject.error(translate.transform('Refresh token failed'));
|
|
853
|
+
return throwError(() => new Error(translate.transform('Refresh token failed')));
|
|
853
854
|
}
|
|
854
855
|
// Phát token mới cho các request đang chờ
|
|
855
856
|
refreshTokenSubject.next(TokenStorage.getToken());
|
|
@@ -1187,6 +1188,7 @@ class BaseComponent {
|
|
|
1187
1188
|
translate = inject(TranslateService);
|
|
1188
1189
|
modal = inject(CustomModalService);
|
|
1189
1190
|
routeSub;
|
|
1191
|
+
backURL = '';
|
|
1190
1192
|
/**
|
|
1191
1193
|
* Khi dùng onRouteChange nhớ dùng unSubRouteChange
|
|
1192
1194
|
*/
|
|
@@ -1201,7 +1203,12 @@ class BaseComponent {
|
|
|
1201
1203
|
this.routeSub?.unsubscribe();
|
|
1202
1204
|
}
|
|
1203
1205
|
goback() {
|
|
1204
|
-
this.
|
|
1206
|
+
if (this.backURL) {
|
|
1207
|
+
this.goto(this.backURL);
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
this.location.back();
|
|
1211
|
+
}
|
|
1205
1212
|
}
|
|
1206
1213
|
goto(url) {
|
|
1207
1214
|
if (url) {
|