@rxap/nest-auth0 11.0.0 → 11.0.1-dev.0
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/CHANGELOG.md +13 -0
- package/TODO.md +52 -0
- package/package.json +3 -4
- package/src/generators/init/generator.js +25 -16
- package/src/lib/auth0-validation-schema.js +1 -1
- package/src/lib/auth0.guard.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 11.0.1-dev.0 (2026-06-19)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- **release:** drop stale per-project release.version overrides
|
|
6
|
+
- **generators:** read package.json and node_modules from disk, not the virtual Tree
|
|
7
|
+
- **nest-auth0:** iterate defaults with Object.entries and fix username typo
|
|
8
|
+
- **generators:** match package name with .some() in init devDependency coercion
|
|
9
|
+
|
|
10
|
+
### ❤️ Thank You
|
|
11
|
+
|
|
12
|
+
- Merzough Münker
|
|
13
|
+
|
|
1
14
|
# Change Log
|
|
2
15
|
|
|
3
16
|
All notable changes to this project will be documented in this file.
|
package/TODO.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# TODO: nest-auth0 Project Audit & Improvements
|
|
2
|
+
|
|
3
|
+
This file lists the findings, bugs, and architectural debt identified during the project audit of the `@rxap/nest-auth0` library.
|
|
4
|
+
|
|
5
|
+
## 🔴 Critical & Functional Bugs
|
|
6
|
+
|
|
7
|
+
### 1. Broken Peer Dependency Initialization in Generator
|
|
8
|
+
- **File:** `src/generators/init/generator.ts`
|
|
9
|
+
- **Line Reference:** [L83-L137](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/auth0/src/generators/init/generator.ts#L83-L137)
|
|
10
|
+
- **Description:**
|
|
11
|
+
The generator adds missing peer dependencies via `addDependenciesToPackageJson` + `installPackagesTask`, then immediately attempts to locate and run their `init` generators in the same run. Since those dependencies are only installed on disk *after* the generator finishes, they are not yet present in `node_modules`, so the newly-added peers cannot be initialized in the same run.
|
|
12
|
+
- **Recommended Fix:** Run installation before calling peer generators, or delegate peer generator invocations to a post-install task or workspace-level generator.
|
|
13
|
+
- **Note:** (virtual-tree/physical-path access was fixed 2026-06; the install-ordering problem remains)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🟡 Architectural Debt & Code Smells
|
|
18
|
+
|
|
19
|
+
### 1. Unregistered and Duplicated `Auth0Service`
|
|
20
|
+
- **File:** `src/lib/auth0.service.ts`
|
|
21
|
+
- **Description:**
|
|
22
|
+
`Auth0Service` is an identical duplicate of `Auth0AuthenticationService`. It is not registered as a provider in `Auth0Module`, is not exported in `index.ts`, and is not used anywhere in the workspace.
|
|
23
|
+
- **Recommended Fix:** Remove `src/lib/auth0.service.ts` and remove its export from `src/index.ts`.
|
|
24
|
+
|
|
25
|
+
### 2. Hybrid Runtime/Build-Time Packaging
|
|
26
|
+
- **Description:**
|
|
27
|
+
The package mixes runtime NestJS code with build-time Nx generators and schematics. This forces `@nx/devkit` to be a runtime `dependency` in `package.json`, which bloats the production dependency graph of downstream applications.
|
|
28
|
+
- **Recommended Fix:** Split the generator and schematic into a separate package (e.g. `@rxap/plugin-nest-auth0` or `@rxap/schematic-nest-auth0`), keeping runtime packages lightweight and free of build tools.
|
|
29
|
+
|
|
30
|
+
### 3. Fallback to Real JWT Verification when Disabled
|
|
31
|
+
- **File:** `src/lib/auth0.guard.ts`
|
|
32
|
+
- **Line Reference:** [L70-L78](file:///mnt/mmuenker/Projects/rxap/packages/packages/nest/auth0/src/lib/auth0.guard.ts#L70-L78)
|
|
33
|
+
- **Description:**
|
|
34
|
+
If `AUTH0_DISABLED` is true but no mock headers are set, the guard falls back to bearer token authentication using `JwtService.verifyAsync()`. This service attempts to connect to the external Auth0 JWKS endpoint. If the issuer URL is missing or unreachable (which is likely if Auth0 is disabled for local/offline dev), it throws a runtime network error or times out.
|
|
35
|
+
- **Recommended Fix:** If `AUTH0_DISABLED` is true, reject the request with a clear 401/403 error immediately rather than attempting standard JWT verification against a potentially unconfigured/offline Auth0 issuer, or fall back to local/static key verification.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 🟢 Test Coverage & Quality Assurance
|
|
40
|
+
|
|
41
|
+
### 1. Zero Test Coverage
|
|
42
|
+
- **Description:**
|
|
43
|
+
The project contains absolutely no test files (`.spec.ts` or `.test.ts`), resulting in 0% test coverage. While `jest` targets and `tsconfig.spec.json` are set up, they do not find any tests.
|
|
44
|
+
- **Recommended Fix:**
|
|
45
|
+
Create test suites under `src/lib/` to cover critical parts of the library:
|
|
46
|
+
- `auth0-validation-schema.spec.ts`: Verify that the Joi validation schema correctly validates configuration options, and that passing custom `defaults` works without throwing.
|
|
47
|
+
- `auth0.guard.ts.spec.ts`: Verify guard behavior when:
|
|
48
|
+
- Auth0 is active and a valid/invalid token is provided.
|
|
49
|
+
- Auth0 is disabled and mock headers (`x-user-id`, etc.) are set or missing.
|
|
50
|
+
- Public and bypass decorators are applied.
|
|
51
|
+
- `auth0-module-options.factory.spec.ts`: Test proper parsing of environment config variables.
|
|
52
|
+
- `generator.spec.ts`: Unit test the schematic/generator with a mock Nx `Tree`.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "11.0.0",
|
|
2
|
+
"version": "11.0.1-dev.0",
|
|
3
3
|
"name": "@rxap/nest-auth0",
|
|
4
4
|
"description": "This package provides an Auth0 module for NestJS applications, simplifying integration with Auth0 for authentication and authorization. It includes a configurable module, JWT strategy, and service for interacting with the Auth0 Authentication API. The module also offers validation schemas for environment variables related to Auth0 configuration.\n",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@nestjs/config": "^4.0.2",
|
|
13
13
|
"@nestjs/core": "^11.1.1",
|
|
14
14
|
"@nestjs/jwt": "^11.0.0",
|
|
15
|
-
"@rxap/nest-utilities": "^11.0.0
|
|
15
|
+
"@rxap/nest-utilities": "^11.0.0",
|
|
16
16
|
"auth0": "^4.18.0",
|
|
17
17
|
"joi": "^17.9.2",
|
|
18
18
|
"jsonwebtoken": "*",
|
|
@@ -47,6 +47,5 @@
|
|
|
47
47
|
},
|
|
48
48
|
"schematics": "./generators.json",
|
|
49
49
|
"type": "commonjs",
|
|
50
|
-
"types": "./src/index.d.ts"
|
|
51
|
-
"gitHead": "36b0e9732b24717840935712e316593ff6aba795"
|
|
50
|
+
"types": "./src/index.d.ts"
|
|
52
51
|
}
|
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initGenerator = initGenerator;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const fs_1 = require("fs");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
async function initGenerator(tree, options) {
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// The package's own package.json lives on disk next to the compiled generator
|
|
9
|
+
// (inside node_modules when installed), which the virtual Tree does not track.
|
|
10
|
+
// Read it directly from the physical filesystem.
|
|
11
|
+
const packageJsonFilePath = (0, path_1.join)(__dirname, '..', '..', '..', 'package.json');
|
|
12
|
+
if (!(0, fs_1.existsSync)(packageJsonFilePath)) {
|
|
9
13
|
console.error('package.json not found in: ' + packageJsonFilePath);
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
|
-
const { peerDependencies, name: packageName } = JSON.parse(
|
|
16
|
+
const { peerDependencies, name: packageName } = JSON.parse((0, fs_1.readFileSync)(packageJsonFilePath, 'utf-8'));
|
|
13
17
|
console.log(`Coerce peer dependencies for package: ${packageName}`);
|
|
14
18
|
if (!peerDependencies || !Object.keys(peerDependencies).length) {
|
|
15
19
|
console.log('No peer dependencies found');
|
|
@@ -27,11 +31,12 @@ async function initGenerator(tree, options) {
|
|
|
27
31
|
isDevDependency = false;
|
|
28
32
|
tree.write('package.json', JSON.stringify(rootPackageJson, null, 2));
|
|
29
33
|
}
|
|
30
|
-
if (!isDevDependency &&
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (!isDevDependency &&
|
|
35
|
+
[
|
|
36
|
+
/^@rxap\/plugin/,
|
|
37
|
+
/^@rxap\/workspace/,
|
|
38
|
+
/@rxap\/schematic/,
|
|
39
|
+
].some((rx) => rx.test(packageName))) {
|
|
35
40
|
rootPackageJson.devDependencies ??= {};
|
|
36
41
|
rootPackageJson.devDependencies[packageName] =
|
|
37
42
|
rootPackageJson.dependencies[packageName];
|
|
@@ -57,35 +62,39 @@ async function initGenerator(tree, options) {
|
|
|
57
62
|
(0, devkit_1.installPackagesTask)(tree);
|
|
58
63
|
for (const peer of Object.keys(missingPeerDependencies)) {
|
|
59
64
|
console.log(`Peer dependency ${peer} added to package.json`);
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
// node_modules is physical and excluded from the virtual Tree, so resolve
|
|
66
|
+
// peer files from disk relative to the workspace root.
|
|
67
|
+
const peerPackageDir = (0, path_1.join)(tree.root, 'node_modules', ...peer.split('/'));
|
|
68
|
+
const peerPackageJsonFilePath = (0, path_1.join)(peerPackageDir, 'package.json');
|
|
69
|
+
if (!(0, fs_1.existsSync)(peerPackageJsonFilePath)) {
|
|
62
70
|
console.log(`Peer dependency ${peer} has no package.json`);
|
|
63
71
|
continue;
|
|
64
72
|
}
|
|
65
|
-
const { generators, schematics } = JSON.parse(
|
|
73
|
+
const { generators, schematics } = JSON.parse((0, fs_1.readFileSync)(peerPackageJsonFilePath, 'utf-8'));
|
|
66
74
|
if (!generators && !schematics) {
|
|
67
75
|
console.log(`Peer dependency ${peer} has no generators or schematics`);
|
|
68
76
|
continue;
|
|
69
77
|
}
|
|
70
78
|
const configFile = generators || schematics;
|
|
71
|
-
|
|
79
|
+
const configFilePath = (0, path_1.join)(peerPackageDir, configFile);
|
|
80
|
+
if (!(0, fs_1.existsSync)(configFilePath)) {
|
|
72
81
|
console.log(`Peer dependency ${peer} has no generators or schematics file`);
|
|
73
82
|
continue;
|
|
74
83
|
}
|
|
75
|
-
const config = JSON.parse(
|
|
84
|
+
const config = JSON.parse((0, fs_1.readFileSync)(configFilePath, 'utf-8'));
|
|
76
85
|
if (!config.generators?.init) {
|
|
77
86
|
console.log(`Peer dependency ${peer} has no init generator`);
|
|
78
87
|
continue;
|
|
79
88
|
}
|
|
80
89
|
const initGeneratorFilePath = config.generators.init.factory;
|
|
81
|
-
const fullInitGeneratorFilePath = (0, path_1.join)(
|
|
82
|
-
if (!
|
|
90
|
+
const fullInitGeneratorFilePath = (0, path_1.join)(peerPackageDir, initGeneratorFilePath) + '.js';
|
|
91
|
+
if (!(0, fs_1.existsSync)(fullInitGeneratorFilePath)) {
|
|
83
92
|
console.log(`Peer dependency ${peer} has no init generator file: ` +
|
|
84
93
|
fullInitGeneratorFilePath);
|
|
85
94
|
continue;
|
|
86
95
|
}
|
|
87
96
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
88
|
-
const initGenerator = require((0, path_1.join)(
|
|
97
|
+
const initGenerator = require((0, path_1.join)(peerPackageDir, initGeneratorFilePath))?.default;
|
|
89
98
|
if (typeof initGenerator !== 'function') {
|
|
90
99
|
console.log(`Peer dependency ${peer} has no init generator function`);
|
|
91
100
|
continue;
|
|
@@ -19,7 +19,7 @@ function auth0ValidationSchema(environment, defaults = {}) {
|
|
|
19
19
|
schema['AUTH0_CLIENT_SECRET'] = Joi.string();
|
|
20
20
|
schema['AUTH0_MANAGEMENT_TOKEN'] = Joi.string();
|
|
21
21
|
schema['AUTH0_DISABLED'] = Joi.boolean();
|
|
22
|
-
for (const [key, value] of Object.
|
|
22
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
23
23
|
if (value) {
|
|
24
24
|
schema[key] = schema[key].default(value);
|
|
25
25
|
}
|
package/src/lib/auth0.guard.js
CHANGED
|
@@ -39,7 +39,7 @@ let Auth0Guard = class Auth0Guard {
|
|
|
39
39
|
user.roles = request.headers['x-user-roles'];
|
|
40
40
|
user.displayName = request.headers['x-user-display-name'];
|
|
41
41
|
user.email = request.headers['x-user-email'];
|
|
42
|
-
user.
|
|
42
|
+
user.username = request.headers['x-user-username'];
|
|
43
43
|
user.name = request.headers['x-user-name'];
|
|
44
44
|
user.nickname = request.headers['x-user-nickname'];
|
|
45
45
|
if (request.user && 'sub' in request.user) {
|