@fluxhub/fluxhub-lib 19.0.73 → 19.0.74
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.
|
@@ -36239,20 +36239,30 @@ class AuthHttpRequestInterceptor {
|
|
|
36239
36239
|
this.http = http;
|
|
36240
36240
|
}
|
|
36241
36241
|
intercept(request, next) {
|
|
36242
|
-
|
|
36243
|
-
|
|
36242
|
+
const token = this.getJwtToken();
|
|
36243
|
+
console.log('[AuthInterceptor] Intercepting request:', request.url);
|
|
36244
|
+
console.log('[AuthInterceptor] Token available:', token !== 'ZZ' && token !== null);
|
|
36245
|
+
if (token && token !== 'ZZ') {
|
|
36246
|
+
request = this.addToken(request, token);
|
|
36247
|
+
console.log('[AuthInterceptor] Token added to request');
|
|
36248
|
+
}
|
|
36249
|
+
else {
|
|
36250
|
+
console.warn('[AuthInterceptor] No valid token found in localStorage');
|
|
36244
36251
|
}
|
|
36245
36252
|
return next.handle(request).pipe(catchError((error) => {
|
|
36246
36253
|
if (error instanceof HttpErrorResponse &&
|
|
36247
36254
|
error.status === 400 &&
|
|
36248
36255
|
error.error === 'Invalid client request') {
|
|
36256
|
+
console.error('[AuthInterceptor] Invalid client request (400)');
|
|
36249
36257
|
this.loginservice.logout();
|
|
36250
36258
|
return throwError(error);
|
|
36251
36259
|
}
|
|
36252
36260
|
if (error instanceof HttpErrorResponse && error.status === 401) {
|
|
36261
|
+
console.warn('[AuthInterceptor] Unauthorized (401) - attempting token refresh');
|
|
36253
36262
|
return this.handle401Error(request, next);
|
|
36254
36263
|
}
|
|
36255
36264
|
else {
|
|
36265
|
+
console.error('[AuthInterceptor] HTTP Error:', error.status, error.message);
|
|
36256
36266
|
return throwError(error);
|
|
36257
36267
|
}
|
|
36258
36268
|
}));
|
|
@@ -36262,26 +36272,38 @@ class AuthHttpRequestInterceptor {
|
|
|
36262
36272
|
}
|
|
36263
36273
|
refreshTokenSubject = new BehaviorSubject(null);
|
|
36264
36274
|
handle401Error(request, next) {
|
|
36265
|
-
if (!localStorage.getItem(this.appService.COMPANY_KEY + 'refreshToken'))
|
|
36275
|
+
if (!localStorage.getItem(this.appService.COMPANY_KEY + 'refreshToken')) {
|
|
36276
|
+
console.warn('[AuthInterceptor] No refreshToken found - cannot refresh');
|
|
36266
36277
|
return next.handle(request);
|
|
36278
|
+
}
|
|
36267
36279
|
const refreshToken = localStorage.getItem(this.appService.COMPANY_KEY + 'refreshToken') ||
|
|
36268
36280
|
'ZZ';
|
|
36269
36281
|
const token = localStorage.getItem(this.appService.COMPANY_KEY + 'token') || 'ZZ';
|
|
36270
36282
|
if (!token || !refreshToken) {
|
|
36283
|
+
console.warn('[AuthInterceptor] Missing token or refreshToken');
|
|
36271
36284
|
return next.handle(request);
|
|
36272
36285
|
}
|
|
36273
36286
|
if (!this.isRefreshing) {
|
|
36287
|
+
console.log('[AuthInterceptor] Starting token refresh...');
|
|
36274
36288
|
this.isRefreshing = true;
|
|
36275
36289
|
this.refreshTokenSubject.next(null);
|
|
36276
36290
|
return this.refreshToken(token, refreshToken).pipe(switchMap((token) => {
|
|
36277
36291
|
this.isRefreshing = false;
|
|
36292
|
+
console.log('[AuthInterceptor] Token refreshed successfully');
|
|
36278
36293
|
this.refreshTokenSubject.next(localStorage.getItem(this.appService.COMPANY_KEY + 'token'));
|
|
36279
36294
|
return next.handle(this.addToken(request, localStorage.getItem(this.appService.COMPANY_KEY + 'token') ||
|
|
36280
36295
|
'ZZ'));
|
|
36296
|
+
}), catchError((error) => {
|
|
36297
|
+
this.isRefreshing = false;
|
|
36298
|
+
console.error('[AuthInterceptor] Token refresh failed:', error);
|
|
36299
|
+
this.loginservice.logout();
|
|
36300
|
+
return throwError(() => error);
|
|
36281
36301
|
}));
|
|
36282
36302
|
}
|
|
36283
36303
|
else {
|
|
36304
|
+
console.log('[AuthInterceptor] Waiting for ongoing token refresh...');
|
|
36284
36305
|
return this.refreshTokenSubject.pipe(filter((token) => token != null), take(1), switchMap((jwt) => {
|
|
36306
|
+
console.log('[AuthInterceptor] Using refreshed token from queue');
|
|
36285
36307
|
return next.handle(this.addToken(request, localStorage.getItem(this.appService.COMPANY_KEY + 'token') ||
|
|
36286
36308
|
'ZZ'));
|
|
36287
36309
|
}));
|
|
@@ -36292,6 +36314,7 @@ class AuthHttpRequestInterceptor {
|
|
|
36292
36314
|
accessToken: token,
|
|
36293
36315
|
refreshToken: refreshToken,
|
|
36294
36316
|
});
|
|
36317
|
+
console.log('[AuthInterceptor] Calling refresh endpoint:', this.appService.API_ENDPOINT + 'token/refresh');
|
|
36295
36318
|
return this.http
|
|
36296
36319
|
.post(this.appService.API_ENDPOINT + 'token/refresh', credentials, {
|
|
36297
36320
|
headers: new HttpHeaders({
|
|
@@ -36300,9 +36323,11 @@ class AuthHttpRequestInterceptor {
|
|
|
36300
36323
|
})
|
|
36301
36324
|
.pipe(tap((res) => {
|
|
36302
36325
|
if ((res.accessToken || 'ND') == 'ND') {
|
|
36326
|
+
console.error('[AuthInterceptor] Refresh response invalid - no accessToken');
|
|
36303
36327
|
this.loginservice.logout();
|
|
36304
36328
|
return;
|
|
36305
36329
|
}
|
|
36330
|
+
console.log('[AuthInterceptor] New tokens saved to localStorage');
|
|
36306
36331
|
localStorage.setItem(this.appService.COMPANY_KEY + 'token', res.accessToken);
|
|
36307
36332
|
localStorage.setItem(this.appService.COMPANY_KEY + 'refreshToken', res.refreshToken);
|
|
36308
36333
|
}));
|