@devstroupe/devkit-cli 1.2.0-beta.3 → 1.2.0-beta.4
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,6 +4,7 @@ import { provideHttpClient, withInterceptors } from '@angular/common/http';
|
|
|
4
4
|
import { provideSpartanHlm } from '@spartan-ng/helm/utils';
|
|
5
5
|
import { routes } from './app.routes';
|
|
6
6
|
import { tenantInterceptor } from './shared/interceptors/tenant.interceptor';
|
|
7
|
+
import { authInterceptor } from './shared/interceptors/auth.interceptor';
|
|
7
8
|
import { DEVKIT_AUTH_SERVICE } from '@devstroupe/devkit-angular';
|
|
8
9
|
import { AuthService } from './core/services/auth.service';
|
|
9
10
|
|
|
@@ -36,7 +37,7 @@ export const appConfig: ApplicationConfig = {
|
|
|
36
37
|
provideRouter(routes),
|
|
37
38
|
{ provide: DEVKIT_AUTH_SERVICE, useExisting: AuthService },
|
|
38
39
|
provideHttpClient(
|
|
39
|
-
withInterceptors([tenantInterceptor])
|
|
40
|
+
withInterceptors([tenantInterceptor, authInterceptor])
|
|
40
41
|
),
|
|
41
42
|
provideIcons({
|
|
42
43
|
lucideMenu,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HttpErrorResponse, HttpInterceptorFn } from '@angular/common/http';
|
|
2
|
+
import { inject } from '@angular/core';
|
|
3
|
+
import { Router } from '@angular/router';
|
|
4
|
+
import { catchError, throwError } from 'rxjs';
|
|
5
|
+
import { AuthService } from '../../core/services/auth.service';
|
|
6
|
+
|
|
7
|
+
const PUBLIC_AUTH_ENDPOINTS = [
|
|
8
|
+
'/api/core/auth/login',
|
|
9
|
+
'/api/core/auth/register',
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
function isPublicAuthRequest(url: string): boolean {
|
|
13
|
+
const path = url.split('?')[0];
|
|
14
|
+
return PUBLIC_AUTH_ENDPOINTS.some((endpoint) => path.endsWith(endpoint));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const authInterceptor: HttpInterceptorFn = (req, next) => {
|
|
18
|
+
const authService = inject(AuthService);
|
|
19
|
+
const router = inject(Router);
|
|
20
|
+
|
|
21
|
+
return next(req).pipe(
|
|
22
|
+
catchError((error: unknown) => {
|
|
23
|
+
if (
|
|
24
|
+
error instanceof HttpErrorResponse
|
|
25
|
+
&& error.status === 401
|
|
26
|
+
&& authService.isAuthenticated
|
|
27
|
+
&& !isPublicAuthRequest(req.url)
|
|
28
|
+
) {
|
|
29
|
+
authService.logout();
|
|
30
|
+
void router.navigate(['/login']);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return throwError(() => error);
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
7
|
+
const node_fs_1 = require("node:fs");
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
7
9
|
const node_test_1 = require("node:test");
|
|
8
10
|
const nest_1 = require("./nest");
|
|
9
11
|
const functional_module_templates_1 = require("./nest/functional-module.templates");
|
|
@@ -45,4 +47,15 @@ const playground_template_1 = require("./ui/playground.template");
|
|
|
45
47
|
strict_1.default.match(playground.html, /<hlm-dialog-content \*hlmDialogPortal>/);
|
|
46
48
|
strict_1.default.match(playground.html, /<hlm-alert-dialog-content \*hlmAlertDialogPortal>/);
|
|
47
49
|
});
|
|
50
|
+
(0, node_test_1.it)('generates global unauthorized-session handling', () => {
|
|
51
|
+
const appRoot = node_path_1.default.resolve(__dirname, '../boilerplates/angular-template/src/app');
|
|
52
|
+
const appConfig = (0, node_fs_1.readFileSync)(node_path_1.default.join(appRoot, 'app.config.ts'), 'utf8');
|
|
53
|
+
const interceptor = (0, node_fs_1.readFileSync)(node_path_1.default.join(appRoot, 'shared/interceptors/auth.interceptor.ts'), 'utf8');
|
|
54
|
+
strict_1.default.match(appConfig, /withInterceptors\(\[tenantInterceptor, authInterceptor\]\)/);
|
|
55
|
+
strict_1.default.match(interceptor, /error\.status === 401/);
|
|
56
|
+
strict_1.default.match(interceptor, /authService\.isAuthenticated/);
|
|
57
|
+
strict_1.default.match(interceptor, /authService\.logout\(\)/);
|
|
58
|
+
strict_1.default.match(interceptor, /router\.navigate\(\['\/login'\]\)/);
|
|
59
|
+
strict_1.default.match(interceptor, /PUBLIC_AUTH_ENDPOINTS/);
|
|
60
|
+
});
|
|
48
61
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devstroupe/devkit-cli",
|
|
3
|
-
"version": "1.2.0-beta.
|
|
3
|
+
"version": "1.2.0-beta.4",
|
|
4
4
|
"description": "DevsTroupe Development Kit CLI — scaffold NestJS+Angular projects, inject Spartan UI, generate CRUDs and audit architectural governance",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"commander": "^12.0.0",
|
|
38
38
|
"fs-extra": "^11.2.0",
|
|
39
|
-
"@devstroupe/devkit-core": "1.2.0-beta.
|
|
39
|
+
"@devstroupe/devkit-core": "1.2.0-beta.4"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/fs-extra": "^11.0.4",
|