@fluxhub/fluxhub-lib 19.0.73 → 19.0.75

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.
@@ -1155,6 +1155,8 @@ class AuthenticationService {
1155
1155
  this.url = this.app_s.API_ENDPOINT + this.app_s.LOGIN_ENDPOINT;
1156
1156
  }
1157
1157
  logout(resetPosition = true) {
1158
+ console.log('[AuthService] LOGOUT called - resetPosition:', resetPosition);
1159
+ console.trace('[AuthService] Logout stack trace');
1158
1160
  this.app_s.user = null;
1159
1161
  this.app_s.user_name = null;
1160
1162
  this.app_s.user_surname = null;
@@ -1166,6 +1168,7 @@ class AuthenticationService {
1166
1168
  this.app_s.token = null;
1167
1169
  localStorage.removeItem(this.app_s.COMPANY_KEY + "token");
1168
1170
  localStorage.removeItem(this.app_s.COMPANY_KEY + "refreshToken");
1171
+ console.log('[AuthService] Tokens removed from localStorage');
1169
1172
  if (resetPosition)
1170
1173
  this.goto_after = '';
1171
1174
  if (this.app_s.LOGIN_EXT != 1)
@@ -1201,19 +1204,23 @@ class AuthenticationService {
1201
1204
  }
1202
1205
  else {
1203
1206
  if (res.token) {
1207
+ console.log('[AuthService] Login successful - saving token to localStorage with key:', this.app_s.COMPANY_KEY + "token");
1204
1208
  localStorage.setItem(this.app_s.COMPANY_KEY + "token", res.token);
1205
1209
  }
1206
1210
  if (res.refreshToken) {
1211
+ console.log('[AuthService] Saving refreshToken to localStorage');
1207
1212
  localStorage.setItem(this.app_s.COMPANY_KEY + "refreshToken", res.refreshToken);
1208
1213
  res.result_data = [{ token: res.token, refreshToken: res.refreshToken }];
1209
1214
  return res || new QGResult();
1210
1215
  }
1211
1216
  if (res.refreshtoken) {
1217
+ console.log('[AuthService] Saving refreshtoken (lowercase) to localStorage');
1212
1218
  localStorage.setItem(this.app_s.COMPANY_KEY + "refreshToken", res.refreshtoken);
1213
1219
  res.result_data = [{ token: res.token, refreshToken: res.refreshtoken }];
1214
1220
  return res || new QGResult();
1215
1221
  }
1216
1222
  if (res.result_data.length > 0) {
1223
+ console.log('[AuthService] Saving token from result_data to localStorage');
1217
1224
  localStorage.setItem(this.app_s.COMPANY_KEY + "token", res.result_data[0].token);
1218
1225
  }
1219
1226
  }
@@ -1519,7 +1526,9 @@ class AuthenticationService {
1519
1526
  checkCredentials() {
1520
1527
  if ("/login" != this.router.url && this.router.url.indexOf("/rp/") == -1)
1521
1528
  this.goto_after = window.location.toString();
1522
- if (localStorage.getItem(this.app_s.COMPANY_KEY + "token") === null) {
1529
+ const hasToken = localStorage.getItem(this.app_s.COMPANY_KEY + "token") !== null;
1530
+ console.log('[AuthService] checkCredentials - hasToken:', hasToken, 'COMPANY_KEY:', this.app_s.COMPANY_KEY);
1531
+ if (!hasToken) {
1523
1532
  return false;
1524
1533
  }
1525
1534
  return true;
@@ -36239,20 +36248,30 @@ class AuthHttpRequestInterceptor {
36239
36248
  this.http = http;
36240
36249
  }
36241
36250
  intercept(request, next) {
36242
- if (this.getJwtToken()) {
36243
- request = this.addToken(request, this.getJwtToken());
36251
+ const token = this.getJwtToken();
36252
+ console.log('[AuthInterceptor] Intercepting request:', request.url);
36253
+ console.log('[AuthInterceptor] Token available:', token !== 'ZZ' && token !== null);
36254
+ if (token && token !== 'ZZ') {
36255
+ request = this.addToken(request, token);
36256
+ console.log('[AuthInterceptor] Token added to request');
36257
+ }
36258
+ else {
36259
+ console.warn('[AuthInterceptor] No valid token found in localStorage');
36244
36260
  }
36245
36261
  return next.handle(request).pipe(catchError((error) => {
36246
36262
  if (error instanceof HttpErrorResponse &&
36247
36263
  error.status === 400 &&
36248
36264
  error.error === 'Invalid client request') {
36265
+ console.error('[AuthInterceptor] Invalid client request (400)');
36249
36266
  this.loginservice.logout();
36250
36267
  return throwError(error);
36251
36268
  }
36252
36269
  if (error instanceof HttpErrorResponse && error.status === 401) {
36270
+ console.warn('[AuthInterceptor] Unauthorized (401) - attempting token refresh');
36253
36271
  return this.handle401Error(request, next);
36254
36272
  }
36255
36273
  else {
36274
+ console.error('[AuthInterceptor] HTTP Error:', error.status, error.message);
36256
36275
  return throwError(error);
36257
36276
  }
36258
36277
  }));
@@ -36262,26 +36281,38 @@ class AuthHttpRequestInterceptor {
36262
36281
  }
36263
36282
  refreshTokenSubject = new BehaviorSubject(null);
36264
36283
  handle401Error(request, next) {
36265
- if (!localStorage.getItem(this.appService.COMPANY_KEY + 'refreshToken'))
36284
+ if (!localStorage.getItem(this.appService.COMPANY_KEY + 'refreshToken')) {
36285
+ console.warn('[AuthInterceptor] No refreshToken found - cannot refresh');
36266
36286
  return next.handle(request);
36287
+ }
36267
36288
  const refreshToken = localStorage.getItem(this.appService.COMPANY_KEY + 'refreshToken') ||
36268
36289
  'ZZ';
36269
36290
  const token = localStorage.getItem(this.appService.COMPANY_KEY + 'token') || 'ZZ';
36270
36291
  if (!token || !refreshToken) {
36292
+ console.warn('[AuthInterceptor] Missing token or refreshToken');
36271
36293
  return next.handle(request);
36272
36294
  }
36273
36295
  if (!this.isRefreshing) {
36296
+ console.log('[AuthInterceptor] Starting token refresh...');
36274
36297
  this.isRefreshing = true;
36275
36298
  this.refreshTokenSubject.next(null);
36276
36299
  return this.refreshToken(token, refreshToken).pipe(switchMap((token) => {
36277
36300
  this.isRefreshing = false;
36301
+ console.log('[AuthInterceptor] Token refreshed successfully');
36278
36302
  this.refreshTokenSubject.next(localStorage.getItem(this.appService.COMPANY_KEY + 'token'));
36279
36303
  return next.handle(this.addToken(request, localStorage.getItem(this.appService.COMPANY_KEY + 'token') ||
36280
36304
  'ZZ'));
36305
+ }), catchError((error) => {
36306
+ this.isRefreshing = false;
36307
+ console.error('[AuthInterceptor] Token refresh failed:', error);
36308
+ this.loginservice.logout();
36309
+ return throwError(() => error);
36281
36310
  }));
36282
36311
  }
36283
36312
  else {
36313
+ console.log('[AuthInterceptor] Waiting for ongoing token refresh...');
36284
36314
  return this.refreshTokenSubject.pipe(filter((token) => token != null), take(1), switchMap((jwt) => {
36315
+ console.log('[AuthInterceptor] Using refreshed token from queue');
36285
36316
  return next.handle(this.addToken(request, localStorage.getItem(this.appService.COMPANY_KEY + 'token') ||
36286
36317
  'ZZ'));
36287
36318
  }));
@@ -36292,6 +36323,7 @@ class AuthHttpRequestInterceptor {
36292
36323
  accessToken: token,
36293
36324
  refreshToken: refreshToken,
36294
36325
  });
36326
+ console.log('[AuthInterceptor] Calling refresh endpoint:', this.appService.API_ENDPOINT + 'token/refresh');
36295
36327
  return this.http
36296
36328
  .post(this.appService.API_ENDPOINT + 'token/refresh', credentials, {
36297
36329
  headers: new HttpHeaders({
@@ -36300,9 +36332,11 @@ class AuthHttpRequestInterceptor {
36300
36332
  })
36301
36333
  .pipe(tap((res) => {
36302
36334
  if ((res.accessToken || 'ND') == 'ND') {
36335
+ console.error('[AuthInterceptor] Refresh response invalid - no accessToken');
36303
36336
  this.loginservice.logout();
36304
36337
  return;
36305
36338
  }
36339
+ console.log('[AuthInterceptor] New tokens saved to localStorage');
36306
36340
  localStorage.setItem(this.appService.COMPANY_KEY + 'token', res.accessToken);
36307
36341
  localStorage.setItem(this.appService.COMPANY_KEY + 'refreshToken', res.refreshToken);
36308
36342
  }));