@cccteam/ccc-lib 0.0.22 → 0.0.23
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/fesm2022/cccteam-ccc-lib-auth-authentication-guard.mjs +3 -2
- package/fesm2022/cccteam-ccc-lib-auth-authentication-guard.mjs.map +1 -1
- package/fesm2022/cccteam-ccc-lib-guards.mjs +3 -3
- package/fesm2022/cccteam-ccc-lib-guards.mjs.map +1 -1
- package/fesm2022/cccteam-ccc-lib-ui-idle-service.mjs +3 -2
- package/fesm2022/cccteam-ccc-lib-ui-idle-service.mjs.map +1 -1
- package/fesm2022/cccteam-ccc-lib-ui-interceptor.mjs +3 -2
- package/fesm2022/cccteam-ccc-lib-ui-interceptor.mjs.map +1 -1
- package/package.json +1 -1
- package/types/cccteam-ccc-lib-ui-idle-service.d.ts +1 -0
- package/types/cccteam-ccc-lib-ui-interceptor.d.ts +1 -0
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { inject } from '@angular/core';
|
|
2
2
|
import { AuthService } from '@cccteam/ccc-lib/auth-service';
|
|
3
|
-
import { BASE_URL } from '@cccteam/ccc-lib/types';
|
|
3
|
+
import { BASE_URL, API_URL } from '@cccteam/ccc-lib/types';
|
|
4
4
|
import { of } from 'rxjs';
|
|
5
5
|
import { map, catchError } from 'rxjs/operators';
|
|
6
6
|
|
|
7
7
|
const AuthenticationGuard = (route, routerState) => {
|
|
8
8
|
const authService = inject(AuthService);
|
|
9
9
|
const baseUrl = inject(BASE_URL);
|
|
10
|
+
const apiUrl = inject(API_URL);
|
|
10
11
|
const authenticate = () => {
|
|
11
12
|
const url = routerState.url;
|
|
12
13
|
const absoluteUrl = baseUrl + (!url.toString().startsWith('/') ? '/' + url : url);
|
|
13
14
|
const encodedUrl = encodeURIComponent(absoluteUrl);
|
|
14
|
-
window.location.href = `${
|
|
15
|
+
window.location.href = `${apiUrl}/user/login?returnUrl=${encodedUrl}`;
|
|
15
16
|
};
|
|
16
17
|
if (authService.authenticated()) {
|
|
17
18
|
return of(true);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cccteam-ccc-lib-auth-authentication-guard.mjs","sources":["../../../projects/ccc-lib/auth-authentication-guard/authentication.guard.ts","../../../projects/ccc-lib/auth-authentication-guard/cccteam-ccc-lib-auth-authentication-guard.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { BASE_URL } from '@cccteam/ccc-lib/types';\nimport { Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nexport const AuthenticationGuard = (\n route: ActivatedRouteSnapshot,\n routerState: RouterStateSnapshot,\n): Observable<boolean> => {\n const authService = inject(AuthService);\n const baseUrl = inject(BASE_URL);\n\n const authenticate = (): void => {\n const url = routerState.url;\n const absoluteUrl = baseUrl + (!url.toString().startsWith('/') ? '/' + url : url);\n const encodedUrl = encodeURIComponent(absoluteUrl);\n window.location.href = `${
|
|
1
|
+
{"version":3,"file":"cccteam-ccc-lib-auth-authentication-guard.mjs","sources":["../../../projects/ccc-lib/auth-authentication-guard/authentication.guard.ts","../../../projects/ccc-lib/auth-authentication-guard/cccteam-ccc-lib-auth-authentication-guard.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { API_URL, BASE_URL } from '@cccteam/ccc-lib/types';\nimport { Observable, of } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nexport const AuthenticationGuard = (\n route: ActivatedRouteSnapshot,\n routerState: RouterStateSnapshot,\n): Observable<boolean> => {\n const authService = inject(AuthService);\n const baseUrl = inject(BASE_URL);\n const apiUrl = inject(API_URL);\n\n const authenticate = (): void => {\n const url = routerState.url;\n const absoluteUrl = baseUrl + (!url.toString().startsWith('/') ? '/' + url : url);\n const encodedUrl = encodeURIComponent(absoluteUrl);\n window.location.href = `${apiUrl}/user/login?returnUrl=${encodedUrl}`;\n };\n\n if (authService.authenticated()) {\n return of(true);\n }\n\n return authService.checkUserSession().pipe(\n map((sessionInfo) => {\n if (sessionInfo?.authenticated) {\n return true;\n }\n\n authenticate();\n return false;\n }),\n catchError(() => {\n authenticate();\n return of(false);\n }),\n );\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;MAOa,mBAAmB,GAAG,CACjC,KAA6B,EAC7B,WAAgC,KACT;AACvB,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AACvC,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC;AAChC,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IAE9B,MAAM,YAAY,GAAG,MAAW;AAC9B,QAAA,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG;QAC3B,MAAM,WAAW,GAAG,OAAO,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AACjF,QAAA,MAAM,UAAU,GAAG,kBAAkB,CAAC,WAAW,CAAC;QAClD,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,GAAG,MAAM,CAAA,sBAAA,EAAyB,UAAU,CAAA,CAAE;AACvE,IAAA,CAAC;AAED,IAAA,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE;AAC/B,QAAA,OAAO,EAAE,CAAC,IAAI,CAAC;IACjB;AAEA,IAAA,OAAO,WAAW,CAAC,gBAAgB,EAAE,CAAC,IAAI,CACxC,GAAG,CAAC,CAAC,WAAW,KAAI;AAClB,QAAA,IAAI,WAAW,EAAE,aAAa,EAAE;AAC9B,YAAA,OAAO,IAAI;QACb;AAEA,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,KAAK;AACd,IAAA,CAAC,CAAC,EACF,UAAU,CAAC,MAAK;AACd,QAAA,YAAY,EAAE;AACd,QAAA,OAAO,EAAE,CAAC,KAAK,CAAC;IAClB,CAAC,CAAC,CACH;AACH;;ACxCA;;AAEG;;;;"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { inject } from '@angular/core';
|
|
2
2
|
import { MatDialog } from '@angular/material/dialog';
|
|
3
|
-
import { AuthService } from '@cccteam/ccc-lib/auth-service';
|
|
4
3
|
import { LeavePageConfirmationModalComponent } from '@cccteam/ccc-lib/ccc-resource-modals';
|
|
5
4
|
import { FormStateService } from '@cccteam/ccc-lib/ccc-resource-services';
|
|
5
|
+
import { FRONTEND_LOGIN_PATH } from '@cccteam/ccc-lib/types';
|
|
6
6
|
import { tap, firstValueFrom } from 'rxjs';
|
|
7
7
|
|
|
8
8
|
const canDeactivateGuard = async (_, __, ___, nextState) => {
|
|
9
|
-
const auth = inject(AuthService);
|
|
10
9
|
const dialog = inject(MatDialog);
|
|
11
10
|
const formStateService = inject(FormStateService);
|
|
12
|
-
|
|
11
|
+
const loginPath = inject(FRONTEND_LOGIN_PATH);
|
|
12
|
+
if (nextState?.url.includes(loginPath)) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
15
|
if (!formStateService.isDirty()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cccteam-ccc-lib-guards.mjs","sources":["../../../projects/ccc-lib/guards/can-deactivate.guard.ts","../../../projects/ccc-lib/guards/cccteam-ccc-lib-guards.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { MatDialog } from '@angular/material/dialog';\nimport { CanDeactivateFn, UrlTree } from '@angular/router';\nimport {
|
|
1
|
+
{"version":3,"file":"cccteam-ccc-lib-guards.mjs","sources":["../../../projects/ccc-lib/guards/can-deactivate.guard.ts","../../../projects/ccc-lib/guards/cccteam-ccc-lib-guards.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { MatDialog } from '@angular/material/dialog';\nimport { CanDeactivateFn, UrlTree } from '@angular/router';\nimport { LeavePageConfirmationModalComponent } from '@cccteam/ccc-lib/ccc-resource-modals';\nimport { FormStateService } from '@cccteam/ccc-lib/ccc-resource-services';\nimport { FRONTEND_LOGIN_PATH } from '@cccteam/ccc-lib/types';\nimport { firstValueFrom, Observable, tap } from 'rxjs';\n\nexport type CanDeactivateType = Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree;\n\nexport interface CanComponentDeactivate {\n canDeactivate: () => CanDeactivateType;\n}\n\nexport const canDeactivateGuard: CanDeactivateFn<CanComponentDeactivate> = async (_, __, ___, nextState) => {\n const dialog = inject(MatDialog);\n const formStateService = inject(FormStateService);\n const loginPath = inject(FRONTEND_LOGIN_PATH);\n\n if (nextState?.url.includes(loginPath)) {\n return true;\n }\n\n if (!formStateService.isDirty()) {\n return true;\n }\n\n const existingDialog = dialog.openDialogs.find(\n (d) => d.componentInstance instanceof LeavePageConfirmationModalComponent,\n );\n\n const dialogRef = existingDialog ?? dialog.open(LeavePageConfirmationModalComponent, { delayFocusTrap: false });\n\n const result = dialogRef.afterClosed().pipe(\n tap((value) => {\n if (value === true) {\n formStateService.resetDirtyForms();\n }\n }),\n );\n\n return firstValueFrom(result);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAcO,MAAM,kBAAkB,GAA4C,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,SAAS,KAAI;AACzG,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;AAChC,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACjD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAE7C,IAAI,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACtC,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE;AAC/B,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAC5C,CAAC,CAAC,KAAK,CAAC,CAAC,iBAAiB,YAAY,mCAAmC,CAC1E;AAED,IAAA,MAAM,SAAS,GAAG,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AAE/G,IAAA,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,IAAI,CACzC,GAAG,CAAC,CAAC,KAAK,KAAI;AACZ,QAAA,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,gBAAgB,CAAC,eAAe,EAAE;QACpC;IACF,CAAC,CAAC,CACH;AAED,IAAA,OAAO,cAAc,CAAC,MAAM,CAAC;AAC/B;;AC1CA;;AAEG;;;;"}
|
|
@@ -3,7 +3,7 @@ import { inject, signal, computed, Injectable } from '@angular/core';
|
|
|
3
3
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
4
4
|
import { Router } from '@angular/router';
|
|
5
5
|
import { AuthService } from '@cccteam/ccc-lib/auth-service';
|
|
6
|
-
import { IDLE_SESSION_DURATION, IDLE_WARNING_DURATION, IDLE_KEEPALIVE_DURATION, AlertLevel } from '@cccteam/ccc-lib/types';
|
|
6
|
+
import { FRONTEND_LOGIN_PATH, IDLE_SESSION_DURATION, IDLE_WARNING_DURATION, IDLE_KEEPALIVE_DURATION, AlertLevel } from '@cccteam/ccc-lib/types';
|
|
7
7
|
import { UiCoreService } from '@cccteam/ccc-lib/ui-core-service';
|
|
8
8
|
import { NotificationService } from '@cccteam/ccc-lib/ui-notification-service';
|
|
9
9
|
import { interval } from 'rxjs';
|
|
@@ -13,6 +13,7 @@ class IdleService {
|
|
|
13
13
|
core = inject(UiCoreService);
|
|
14
14
|
router = inject(Router);
|
|
15
15
|
notifications = inject(NotificationService);
|
|
16
|
+
loginPath = inject(FRONTEND_LOGIN_PATH);
|
|
16
17
|
sessionDuration = inject(IDLE_SESSION_DURATION);
|
|
17
18
|
warningDuration = inject(IDLE_WARNING_DURATION);
|
|
18
19
|
keepAliveDuration = inject(IDLE_KEEPALIVE_DURATION);
|
|
@@ -73,7 +74,7 @@ class IdleService {
|
|
|
73
74
|
*/
|
|
74
75
|
logoutAndStop() {
|
|
75
76
|
this.stop();
|
|
76
|
-
this.router.navigate([this.
|
|
77
|
+
this.router.navigate([this.loginPath]);
|
|
77
78
|
this.core.publishError({
|
|
78
79
|
message: 'You have been logged out due to inactivity.',
|
|
79
80
|
level: AlertLevel.INFO,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cccteam-ccc-lib-ui-idle-service.mjs","sources":["../../../projects/ccc-lib/ui-idle-service/idle.service.ts","../../../projects/ccc-lib/ui-idle-service/cccteam-ccc-lib-ui-idle-service.ts"],"sourcesContent":["import { computed, inject, Injectable, OnDestroy, signal, WritableSignal } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { Router } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport {\n AlertLevel,\n IDLE_KEEPALIVE_DURATION,\n IDLE_SESSION_DURATION,\n IDLE_WARNING_DURATION,\n} from '@cccteam/ccc-lib/types';\nimport { UiCoreService } from '@cccteam/ccc-lib/ui-core-service';\nimport { NotificationService } from '@cccteam/ccc-lib/ui-notification-service';\nimport { interval, Subscription } from 'rxjs';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class IdleService implements OnDestroy {\n private auth = inject(AuthService);\n private core = inject(UiCoreService);\n private router = inject(Router);\n private notifications = inject(NotificationService);\n\n private readonly sessionDuration = inject(IDLE_SESSION_DURATION);\n private readonly warningDuration = inject(IDLE_WARNING_DURATION);\n private readonly keepAliveDuration = inject(IDLE_KEEPALIVE_DURATION);\n private readonly idleCheckFrequency = 1000;\n private readonly warningThreshold = this.sessionDuration - this.warningDuration;\n\n public readonly isActive = signal(false);\n private lastActivityTimestamp: WritableSignal<number> = signal(0);\n private tick = signal(Date.now());\n\n public readonly secondsIdle = computed(() => {\n if (!this.isActive() || this.lastActivityTimestamp() === 0) {\n return 0;\n }\n // Depends on tick() to force re-evaluation as time passes\n return Math.floor((this.tick() - this.lastActivityTimestamp()) / 1000);\n });\n\n public readonly isWarning = computed(() => this.secondsIdle() >= this.warningThreshold);\n public readonly countdown = computed(() => {\n if (!this.isWarning()) {\n return 0;\n }\n const remaining = this.sessionDuration - this.secondsIdle();\n return Math.max(0, remaining);\n });\n\n private alertId: number | undefined;\n private mainTickerSubscription: Subscription | undefined;\n\n private readonly activityEvents = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'click'];\n\n constructor() {\n interval(this.keepAliveDuration * 1000)\n .pipe(takeUntilDestroyed())\n .subscribe(() => this.checkSession());\n }\n\n ngOnDestroy(): void {\n this.stop();\n }\n\n /**\n * Starts the idle monitoring service.\n */\n start(): void {\n if (this.isActive()) {\n return;\n }\n this.isActive.set(true);\n this.lastActivityTimestamp.set(Date.now());\n this.addActivityListeners();\n this.startMainTicker();\n }\n\n /**\n * Stops the idle monitoring service and cleans up timers and alerts.\n */\n stop(): void {\n this.isActive.set(false);\n this.mainTickerSubscription?.unsubscribe();\n this.removeActivityListeners();\n this.dismissWarningAlert();\n }\n\n /**\n * Logs out the user due to inactivity and stops the service.\n */\n logoutAndStop(): void {\n this.stop();\n\n this.router.navigate([this.
|
|
1
|
+
{"version":3,"file":"cccteam-ccc-lib-ui-idle-service.mjs","sources":["../../../projects/ccc-lib/ui-idle-service/idle.service.ts","../../../projects/ccc-lib/ui-idle-service/cccteam-ccc-lib-ui-idle-service.ts"],"sourcesContent":["import { computed, inject, Injectable, OnDestroy, signal, WritableSignal } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { Router } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport {\n AlertLevel,\n FRONTEND_LOGIN_PATH,\n IDLE_KEEPALIVE_DURATION,\n IDLE_SESSION_DURATION,\n IDLE_WARNING_DURATION,\n} from '@cccteam/ccc-lib/types';\nimport { UiCoreService } from '@cccteam/ccc-lib/ui-core-service';\nimport { NotificationService } from '@cccteam/ccc-lib/ui-notification-service';\nimport { interval, Subscription } from 'rxjs';\n\n@Injectable({\n providedIn: 'root',\n})\nexport class IdleService implements OnDestroy {\n private auth = inject(AuthService);\n private core = inject(UiCoreService);\n private router = inject(Router);\n private notifications = inject(NotificationService);\n private readonly loginPath = inject(FRONTEND_LOGIN_PATH);\n\n private readonly sessionDuration = inject(IDLE_SESSION_DURATION);\n private readonly warningDuration = inject(IDLE_WARNING_DURATION);\n private readonly keepAliveDuration = inject(IDLE_KEEPALIVE_DURATION);\n private readonly idleCheckFrequency = 1000;\n private readonly warningThreshold = this.sessionDuration - this.warningDuration;\n\n public readonly isActive = signal(false);\n private lastActivityTimestamp: WritableSignal<number> = signal(0);\n private tick = signal(Date.now());\n\n public readonly secondsIdle = computed(() => {\n if (!this.isActive() || this.lastActivityTimestamp() === 0) {\n return 0;\n }\n // Depends on tick() to force re-evaluation as time passes\n return Math.floor((this.tick() - this.lastActivityTimestamp()) / 1000);\n });\n\n public readonly isWarning = computed(() => this.secondsIdle() >= this.warningThreshold);\n public readonly countdown = computed(() => {\n if (!this.isWarning()) {\n return 0;\n }\n const remaining = this.sessionDuration - this.secondsIdle();\n return Math.max(0, remaining);\n });\n\n private alertId: number | undefined;\n private mainTickerSubscription: Subscription | undefined;\n\n private readonly activityEvents = ['mousedown', 'mousemove', 'keypress', 'scroll', 'touchstart', 'click'];\n\n constructor() {\n interval(this.keepAliveDuration * 1000)\n .pipe(takeUntilDestroyed())\n .subscribe(() => this.checkSession());\n }\n\n ngOnDestroy(): void {\n this.stop();\n }\n\n /**\n * Starts the idle monitoring service.\n */\n start(): void {\n if (this.isActive()) {\n return;\n }\n this.isActive.set(true);\n this.lastActivityTimestamp.set(Date.now());\n this.addActivityListeners();\n this.startMainTicker();\n }\n\n /**\n * Stops the idle monitoring service and cleans up timers and alerts.\n */\n stop(): void {\n this.isActive.set(false);\n this.mainTickerSubscription?.unsubscribe();\n this.removeActivityListeners();\n this.dismissWarningAlert();\n }\n\n /**\n * Logs out the user due to inactivity and stops the service.\n */\n logoutAndStop(): void {\n this.stop();\n\n this.router.navigate([this.loginPath]);\n this.core.publishError({\n message: 'You have been logged out due to inactivity.',\n level: AlertLevel.INFO,\n link: '',\n });\n }\n\n private startMainTicker(): void {\n this.mainTickerSubscription = interval(this.idleCheckFrequency).subscribe(() => {\n this.tick.set(Date.now());\n\n if (this.secondsIdle() >= this.sessionDuration) {\n this.logoutAndStop();\n return;\n }\n\n if (this.isWarning()) {\n this.showOrUpdateWarningAlert(this.countdown());\n } else {\n this.dismissWarningAlert();\n }\n });\n }\n\n private checkSession(): void {\n if (this.auth.authenticated()) {\n this.auth.checkUserSession().subscribe({\n next: () => {\n if (!this.auth.authenticated()) {\n this.logoutAndStop();\n }\n },\n });\n }\n }\n\n setLastActivity(): void {\n this.lastActivityTimestamp.set(Date.now());\n }\n boundActivity = this.setLastActivity.bind(this);\n\n private addActivityListeners(): void {\n this.activityEvents.forEach((event) => {\n document.addEventListener(event, this.boundActivity, true);\n });\n }\n\n private removeActivityListeners(): void {\n this.activityEvents.forEach((event) => {\n document.removeEventListener(event, this.boundActivity, true);\n });\n }\n\n private showOrUpdateWarningAlert(countdown: number): void {\n const message = `You will be logged out in ${countdown} seconds due to inactivity.`;\n if (this.alertId !== undefined) {\n this.notifications.updateNotification({ id: this.alertId, level: AlertLevel.INFO, link: '', message });\n } else {\n this.alertId = this.notifications.addGlobalNotification({\n message,\n level: AlertLevel.INFO,\n link: '',\n });\n }\n }\n\n private dismissWarningAlert(): void {\n if (this.alertId !== undefined) {\n this.notifications.dismissGlobalNotificationById(this.alertId);\n this.alertId = undefined;\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nex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IAAA,EAAA,WAAW,cAFV,MAAM,EAAA,CAAA;;2FAEP,WAAW,EAAA,UAAA,EAAA,CAAA;kBAHvB,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA;;;ACjBD;;AAEG;;;;"}
|
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { inject, NgZone, Injectable } from '@angular/core';
|
|
3
3
|
import { Router } from '@angular/router';
|
|
4
4
|
import { AuthService } from '@cccteam/ccc-lib/auth-service';
|
|
5
|
-
import { BASE_URL, AlertLevel } from '@cccteam/ccc-lib/types';
|
|
5
|
+
import { BASE_URL, FRONTEND_LOGIN_PATH, AlertLevel } from '@cccteam/ccc-lib/types';
|
|
6
6
|
import { UiCoreService } from '@cccteam/ccc-lib/ui-core-service';
|
|
7
7
|
import { CUSTOM_HTTP_REQUEST_OPTIONS } from '@cccteam/ccc-lib/util-request-options';
|
|
8
8
|
import { catchError, throwError, finalize } from 'rxjs';
|
|
@@ -13,13 +13,14 @@ class ApiInterceptor {
|
|
|
13
13
|
router = inject(Router);
|
|
14
14
|
ngZone = inject(NgZone);
|
|
15
15
|
baseUrl = inject(BASE_URL);
|
|
16
|
+
loginPath = inject(FRONTEND_LOGIN_PATH);
|
|
16
17
|
intercept(request, next) {
|
|
17
18
|
this.ui.beginActivity(request.method + ' ' + request.url);
|
|
18
19
|
return next.handle(request).pipe(catchError((error) => {
|
|
19
20
|
if (error.status === 401) {
|
|
20
21
|
this.ngZone.run(() => {
|
|
21
22
|
this.auth.redirectUrl.set(this.baseUrl + this.router.url);
|
|
22
|
-
this.router.navigate([this.
|
|
23
|
+
this.router.navigate([this.loginPath]);
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
if (!request.context.get(CUSTOM_HTTP_REQUEST_OPTIONS).suppressGlobalError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cccteam-ccc-lib-ui-interceptor.mjs","sources":["../../../projects/ccc-lib/ui-interceptor/api.interceptor.ts","../../../projects/ccc-lib/ui-interceptor/cccteam-ccc-lib-ui-interceptor.ts"],"sourcesContent":["import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';\nimport { inject, Injectable, NgZone } from '@angular/core';\nimport { Router } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { AlertLevel, BASE_URL } from '@cccteam/ccc-lib/types';\nimport { UiCoreService } from '@cccteam/ccc-lib/ui-core-service';\nimport { CUSTOM_HTTP_REQUEST_OPTIONS } from '@cccteam/ccc-lib/util-request-options';\nimport { catchError, finalize, Observable, throwError } from 'rxjs';\n\n@Injectable()\nexport class ApiInterceptor implements HttpInterceptor {\n private ui = inject(UiCoreService);\n private auth = inject(AuthService);\n private router = inject(Router);\n private ngZone = inject(NgZone);\n private baseUrl = inject(BASE_URL);\n\n intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n this.ui.beginActivity(request.method + ' ' + request.url);\n\n return next.handle(request).pipe(\n catchError((error: HttpErrorResponse): Observable<HttpEvent<unknown>> => {\n if (error.status === 401) {\n this.ngZone.run(() => {\n this.auth.redirectUrl.set(this.baseUrl + this.router.url);\n this.router.navigate([this.
|
|
1
|
+
{"version":3,"file":"cccteam-ccc-lib-ui-interceptor.mjs","sources":["../../../projects/ccc-lib/ui-interceptor/api.interceptor.ts","../../../projects/ccc-lib/ui-interceptor/cccteam-ccc-lib-ui-interceptor.ts"],"sourcesContent":["import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';\nimport { inject, Injectable, NgZone } from '@angular/core';\nimport { Router } from '@angular/router';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { AlertLevel, BASE_URL, FRONTEND_LOGIN_PATH } from '@cccteam/ccc-lib/types';\nimport { UiCoreService } from '@cccteam/ccc-lib/ui-core-service';\nimport { CUSTOM_HTTP_REQUEST_OPTIONS } from '@cccteam/ccc-lib/util-request-options';\nimport { catchError, finalize, Observable, throwError } from 'rxjs';\n\n@Injectable()\nexport class ApiInterceptor implements HttpInterceptor {\n private ui = inject(UiCoreService);\n private auth = inject(AuthService);\n private router = inject(Router);\n private ngZone = inject(NgZone);\n private baseUrl = inject(BASE_URL);\n private loginPath = inject(FRONTEND_LOGIN_PATH);\n\n intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {\n this.ui.beginActivity(request.method + ' ' + request.url);\n\n return next.handle(request).pipe(\n catchError((error: HttpErrorResponse): Observable<HttpEvent<unknown>> => {\n if (error.status === 401) {\n this.ngZone.run(() => {\n this.auth.redirectUrl.set(this.baseUrl + this.router.url);\n this.router.navigate([this.loginPath]);\n });\n }\n if (!request.context.get(CUSTOM_HTTP_REQUEST_OPTIONS).suppressGlobalError) {\n const message = error.error?.message ?? error.message ?? error.error;\n this.ui.publishError({\n message: message,\n level: AlertLevel.ERROR,\n link: '',\n });\n }\n\n return throwError(() => error);\n }),\n finalize(() => {\n this.ui.endActivity(request.method + ' ' + request.url);\n }),\n );\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;MAUa,cAAc,CAAA;AACjB,IAAA,EAAE,GAAG,MAAM,CAAC,aAAa,CAAC;AAC1B,IAAA,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC;AAC1B,IAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AACvB,IAAA,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AACvB,IAAA,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC;AAC1B,IAAA,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAE/C,SAAS,CAAC,OAA6B,EAAE,IAAiB,EAAA;AACxD,QAAA,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,GAAG,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,EAAA,CAAA;kBAD1B;;;ACTD;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -8,6 +8,7 @@ declare class ApiInterceptor implements HttpInterceptor {
|
|
|
8
8
|
private router;
|
|
9
9
|
private ngZone;
|
|
10
10
|
private baseUrl;
|
|
11
|
+
private loginPath;
|
|
11
12
|
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>>;
|
|
12
13
|
static ɵfac: i0.ɵɵFactoryDeclaration<ApiInterceptor, never>;
|
|
13
14
|
static ɵprov: i0.ɵɵInjectableDeclaration<ApiInterceptor>;
|