very-express 0.9.0-alpha → 0.9.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/AGENTS.md +24 -10
- package/dist/index.js +747 -969
- package/dist/templates/_middlewares/Authentication.ts +0 -3
- package/dist/templates/_middlewares/UserContext.ts +1 -18
- package/dist/templates/_projectSettings/env +13 -12
- package/dist/templates/_projectSettings/package.json +2 -2
- package/dist/templates/_routes/FirebaseAuthUI.gen.ts +20 -0
- package/dist/templates/_routes/LoginUI.ts +293 -242
- package/dist/templates/_services/TypeOrmRepositoryAdapter.ts +0 -6
- package/dist/templates/_services/VexDbConnector.ts +1 -26
- package/dist/templates/_services/auth/JWTService.ts +0 -15
- package/dist/templates/_types/auth.ts +12 -8
- package/dist/templates/_utils/hash.ts +0 -16
- package/dist/templates/root/public/js/deleteaccount.js +0 -54
- package/docs/appGenerated/auth.md +84 -0
- package/docs/architecture/authAndRouting.md +1 -1
- package/docs/architecture/databaseTargets.md +4 -2
- package/docs/features/accountDeletion.md +2 -3
- package/docs/features/auditFields.md +2 -2
- package/docs/releaseNote/v0-8-5.md +98 -0
- package/docs/releaseNote/v0-9-0.md +41 -47
- package/docs/superpowers/specs/2026-09-22-usercontext-audit-enforcement-design.md +9 -9
- package/docs/vexJsonSchema.md +17 -0
- package/package.json +1 -1
- package/vex.config.json +1 -6
- package/dist/templates/_routes/ExternalIdentityUI.gen.ts +0 -20
- package/dist/templates/root/public/js/externallogin.js +0 -133
- package/docs/features/auth.md +0 -34
- package/docs/features/externalIdentity.md +0 -163
- /package/docs/{ForeignKey.md → features/ForeignKey.md} +0 -0
- /package/docs/{apiUsage.md → features/apiUsage.md} +0 -0
|
@@ -25,8 +25,6 @@ class Authentication {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
private async handle(req: Request, next: NextFunction): Promise<void> {
|
|
28
|
-
// gate keeper
|
|
29
|
-
// log.info("Authentication.middleware", req.headers["x-auth-index"], req.headers.authorization);
|
|
30
28
|
const token = req.headers.authorization?.split(" ")[1];
|
|
31
29
|
const accessTokenIndex = req.headers["x-auth-index"]?.toString();
|
|
32
30
|
|
|
@@ -38,7 +36,6 @@ class Authentication {
|
|
|
38
36
|
throw 401;
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
// verify token
|
|
42
39
|
const tokenData = this.JWTService.verifyToken(token, accessTokenIndex);
|
|
43
40
|
|
|
44
41
|
// The signature only proves the token was issued; it says nothing about the account still
|
|
@@ -20,32 +20,15 @@ export function userIdOfToken(tokenData: Record<string, unknown> | undefined): s
|
|
|
20
20
|
const als = new AsyncLocalStorage<UserContextData>();
|
|
21
21
|
|
|
22
22
|
class UserContext {
|
|
23
|
-
/**
|
|
24
|
-
* Enter the per-request identity context.
|
|
25
|
-
*
|
|
26
|
-
* Called ONLY by Authentication.middleware, after token verification succeeded — at
|
|
27
|
-
* that point a verified token always exists, so this runs unconditionally. The store
|
|
28
|
-
* is the request's context; whether it carries a usable identity is decided when it
|
|
29
|
-
* is read (`userId`), not when it is created.
|
|
30
|
-
*
|
|
31
|
-
* Never use `enterWith()`: it mutates the current execution context instead of
|
|
32
|
-
* scoping a new one, and leaks into whatever runs next on the same tick.
|
|
33
|
-
*/
|
|
34
23
|
run<T>(tokenData: Record<string, unknown>, fn: () => T): T {
|
|
35
24
|
return als.run({ tokenData }, fn);
|
|
36
25
|
}
|
|
37
26
|
|
|
38
|
-
/** Current store from the per-request async context. */
|
|
39
27
|
getStore(): UserContextData | undefined {
|
|
40
28
|
return als.getStore();
|
|
41
29
|
}
|
|
42
30
|
|
|
43
|
-
/**
|
|
44
|
-
* Normalized identity of the authenticated caller.
|
|
45
|
-
*
|
|
46
|
-
* The data layer MUST read the identity through this accessor and never inspect the
|
|
47
|
-
* token shape itself — that keeps the token → identity mapping in exactly one place.
|
|
48
|
-
*/
|
|
31
|
+
/** Normalized identity of the authenticated caller. */
|
|
49
32
|
get userId(): string | undefined {
|
|
50
33
|
return userIdOfToken(als.getStore()?.tokenData);
|
|
51
34
|
}
|
|
@@ -19,18 +19,19 @@ OAUTH_GITHUB_CLIENTSECRET=
|
|
|
19
19
|
# OAUTH_APPLE_CLIENTID=
|
|
20
20
|
# OAUTH_APPLE_CLIENTSECRET=
|
|
21
21
|
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
# FIREBASE (auth.firebase in vex.config.json) — see docs/appGenerated/auth.md
|
|
23
|
+
# Server credential: firebase-admin verifies ID tokens, so the project's service account is required.
|
|
24
|
+
# The JSON itself, as one value — generate it in the Firebase console:
|
|
25
|
+
# Project settings > Service accounts > Generate new private key.
|
|
26
|
+
FIREBASE_SERVICE_ACCOUNT_JSON=
|
|
27
|
+
# Browser config: Firebase's *public* web app values, served to the login page by design. There is no
|
|
28
|
+
# secret among them, and no appId — Firebase Auth does not read one.
|
|
29
|
+
FIREBASE_WEB_API_KEY=
|
|
30
|
+
FIREBASE_WEB_AUTH_DOMAIN=
|
|
31
|
+
FIREBASE_WEB_PROJECT_ID=
|
|
32
|
+
# Optional: which sign-in methods the login page renders a button for, comma separated. Defaults to
|
|
33
|
+
# google. The server accepts any provider it knows regardless of this list.
|
|
34
|
+
# FIREBASE_PROVIDERS=google
|
|
34
35
|
|
|
35
36
|
# JWT token
|
|
36
37
|
ACCESS_TOKEN_EXPIRE_TIME='1h'
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"scripts": {
|
|
4
4
|
"build": "npm run openapi && tsc -p . && node scripts/build.js",
|
|
5
5
|
"start": "node dist/server.js",
|
|
6
|
-
"dev": "nodemon --watch src --
|
|
6
|
+
"dev": "nodemon --watch src --ext ts --ignore src/system/_routes/tsoa_routes.ts --ignore src/openapi/ --exec \"tsoa spec-and-routes && ts-node src/server.ts\"",
|
|
7
7
|
"openapi": "tsoa spec-and-routes",
|
|
8
8
|
"docker-build": "docker build -t very-express .",
|
|
9
9
|
"docker-start": "docker run -p 3000:3000 very-express"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"cookie-parser": "^1.4.6",
|
|
14
14
|
"dotenv": "^16.4.4",
|
|
15
15
|
"express": "^4.18.2",
|
|
16
|
-
"firebase": "^
|
|
16
|
+
"firebase-admin": "^14.1.0",
|
|
17
17
|
"helmet": "^7.1.0",
|
|
18
18
|
"js-yaml": "^4.1.0",
|
|
19
19
|
"jsonwebtoken": "^9.0.2",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// {{headerComment}}
|
|
2
|
+
import type { FirebaseAuthUI } from "./LoginUI.gen";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Test/compile-time stand-in for the generated login-page wiring.
|
|
6
|
+
*
|
|
7
|
+
* **In a generated app this file is overwritten by the generator**, which emits the Firebase wiring or
|
|
8
|
+
* `undefined` when `auth.firebase` is off. It lives in the template directory so that `LoginUI.ts`'s
|
|
9
|
+
* unconditional import resolves in this repo — that import has to be unconditional, because the
|
|
10
|
+
* generated default is how the configuration reaches the login page without editing the app-owned
|
|
11
|
+
* `server.ts`.
|
|
12
|
+
*
|
|
13
|
+
* `let` plus a setter rather than a `const`, so the unit tests can vary what the generator "emitted".
|
|
14
|
+
* The generated version is a plain `const`; nothing in the app calls the setter.
|
|
15
|
+
*/
|
|
16
|
+
export let firebaseAuthUI: FirebaseAuthUI | undefined = undefined;
|
|
17
|
+
|
|
18
|
+
export function setFirebaseAuthUI(ui: FirebaseAuthUI | undefined): void {
|
|
19
|
+
firebaseAuthUI = ui;
|
|
20
|
+
}
|