very-express 0.8.4 → 0.8.5
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 +21 -3
- package/dist/index.js +645 -326
- package/dist/templates/_middlewares/UserContext.ts +1 -18
- package/dist/templates/_projectSettings/env +14 -0
- package/dist/templates/_projectSettings/package.json +1 -0
- package/dist/templates/_routes/FirebaseAuthUI.gen.ts +20 -0
- package/dist/templates/_routes/LoginUI.ts +441 -10
- package/dist/templates/_services/oauth/OAuthProfileMap.ts +2 -2
- package/dist/templates/_services/oauth/OAuthStrategyService.ts +5 -5
- package/dist/templates/_types/auth.ts +12 -0
- package/dist/templates/jsonSchema/UserAuthProfiles.json +13 -5
- package/docs/appGenerated/auth.md +83 -22
- package/docs/architecture/authAndRouting.md +1 -1
- package/docs/architecture/databaseTargets.md +1 -1
- package/docs/features/accountDeletion.md +1 -2
- package/docs/features/auditFields.md +2 -2
- package/docs/releaseNote/v0-8-4.md +131 -0
- package/docs/releaseNote/v0-8-5.md +98 -0
- package/docs/superpowers/specs/2026-09-22-usercontext-audit-enforcement-design.md +9 -9
- package/package.json +1 -1
- package/vex.config.json +1 -0
- /package/docs/{ForeignKey.md → features/ForeignKey.md} +0 -0
- /package/docs/{apiUsage.md → features/apiUsage.md} +0 -0
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
"methods": [],
|
|
6
6
|
"joinWhitelist": []
|
|
7
7
|
},
|
|
8
|
-
"documentName": "UserAuthProfiles"
|
|
8
|
+
"documentName": "UserAuthProfiles",
|
|
9
|
+
"uniqueIndex": [
|
|
10
|
+
[
|
|
11
|
+
"provider",
|
|
12
|
+
"providerUserId"
|
|
13
|
+
]
|
|
14
|
+
]
|
|
9
15
|
},
|
|
10
16
|
"properties": {
|
|
11
17
|
"_id": {
|
|
@@ -25,11 +31,13 @@
|
|
|
25
31
|
},
|
|
26
32
|
"provider": {
|
|
27
33
|
"type": "string",
|
|
28
|
-
"index": true
|
|
34
|
+
"index": true,
|
|
35
|
+
"description": "Namespace label of the identity source: an upstream IdP (\"google\"), a broker (\"firebase\"), or vex's own password path (\"local\"). The value \"local\" is reserved."
|
|
29
36
|
},
|
|
30
|
-
"
|
|
37
|
+
"providerUserId": {
|
|
31
38
|
"type": "string",
|
|
32
|
-
"index": true
|
|
39
|
+
"index": true,
|
|
40
|
+
"description": "External subject within `provider`'s namespace. With `provider` it forms the account-linking key and the composite unique index. NULL for provider=\"local\". This is the subject (an OIDC `sub` or a broker user id), never a token."
|
|
33
41
|
},
|
|
34
42
|
"email": {
|
|
35
43
|
"type": "string"
|
|
@@ -42,4 +50,4 @@
|
|
|
42
50
|
"x-hidden": true
|
|
43
51
|
}
|
|
44
52
|
}
|
|
45
|
-
}
|
|
53
|
+
}
|
|
@@ -1,23 +1,84 @@
|
|
|
1
1
|
# Auth
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
|
|
3
|
+
Stateless JWT tokens, plus three independent sign-in paths: local (email + password), OAuth2
|
|
4
|
+
(passport), and Firebase.
|
|
5
|
+
|
|
6
|
+
## Tokens
|
|
7
|
+
|
|
8
|
+
Rolling keys are defined in `.env` as `JWT_KEY{increment}`:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
JWT_KEY1=aaaaa
|
|
12
|
+
JWT_KEY2=bbbbb
|
|
13
|
+
JWT_KEY3=ccccc
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
A client sends the access token as `Authorization: Bearer <accessToken>` with
|
|
17
|
+
`X-Auth-Index: <accessTokenIndex>`, and refreshes at `POST /api/auth/refresh`.
|
|
18
|
+
|
|
19
|
+
## Sign-in paths
|
|
20
|
+
|
|
21
|
+
| Path | Endpoint | Enabled by |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| Local (email + password) | `POST /api/auth/local`, `POST /api/auth/register` | `auth.localAuth` |
|
|
24
|
+
| OAuth2 | `GET /api/auth/<provider>` → `GET /api/auth/<provider>/callback` | `auth.oauthProviders` |
|
|
25
|
+
| Firebase | `POST /api/auth/firebase` | `auth.firebase` |
|
|
26
|
+
|
|
27
|
+
Local and OAuth2 answer `302` with a single-use `sessionCode`, which the client exchanges at
|
|
28
|
+
`POST /api/auth/token` for the token pair. Firebase answers `200` with the token pair directly.
|
|
29
|
+
|
|
30
|
+
OAuth2 credentials come from `.env`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
OAUTH_GOOGLE_CLIENTID=xxxxx
|
|
34
|
+
OAUTH_GOOGLE_CLIENTSECRET=xxxxx
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`/login` renders a form or a button for whichever paths are enabled.
|
|
38
|
+
|
|
39
|
+
## The identity row
|
|
40
|
+
|
|
41
|
+
A sign-in writes one `UserAuthProfiles` row, keyed by `(provider, providerUserId)` — a composite unique
|
|
42
|
+
index. `provider` is the namespace, `providerUserId` the subject inside it:
|
|
43
|
+
|
|
44
|
+
| Sign-in | `provider` | `providerUserId` |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| Local | `local` | — |
|
|
47
|
+
| passport Google | `google` | Google `sub` (`profile.id`) |
|
|
48
|
+
| Firebase + Google | `google` | Google `sub` |
|
|
49
|
+
| Firebase email/password, phone | — | `400`, no row |
|
|
50
|
+
|
|
51
|
+
A user reaching the API through Firebase and through passport Google resolves to the same `User` row.
|
|
52
|
+
`provider: "local"` is reserved: `verifyPassword` looks rows up by it.
|
|
53
|
+
|
|
54
|
+
## Firebase
|
|
55
|
+
|
|
56
|
+
```jsonc
|
|
57
|
+
"auth": { "firebase": true }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
FIREBASE_SERVICE_ACCOUNT_JSON= # the service account JSON
|
|
62
|
+
FIREBASE_WEB_API_KEY= # public browser config, served to /login
|
|
63
|
+
FIREBASE_WEB_AUTH_DOMAIN=
|
|
64
|
+
FIREBASE_WEB_PROJECT_ID=
|
|
65
|
+
# FIREBASE_PROVIDERS=google # which buttons /login renders; default google
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The server verifies the ID token with `firebase-admin` against the project named by the service
|
|
69
|
+
account. With no usable credential the endpoint answers `503` and the app still starts.
|
|
70
|
+
|
|
71
|
+
`/login` loads the modular SDK (`firebase-app.js` / `firebase-auth.js`, ES modules from gstatic, pinned
|
|
72
|
+
version), preloads it on page load, and calls `signInWithPopup(getAuth(app), provider)` followed by
|
|
73
|
+
`user.getIdToken()`. The page sets its own CSP (script/connect/frame hosts) and its own
|
|
74
|
+
`Cross-Origin-Opener-Policy: same-origin-allow-popups`.
|
|
75
|
+
|
|
76
|
+
`firebase.sign_in_provider` selects the provider and `firebase.identities[<provider>][0]` supplies the
|
|
77
|
+
subject. A token whose provider has no entry in that map, or whose subject is missing, is answered with
|
|
78
|
+
`400`.
|
|
79
|
+
|
|
80
|
+
Failure modes on the page, expanded from the SDK's codes into a message on screen and in the server
|
|
81
|
+
log: `auth/popup-blocked`, `auth/popup-closed-by-user` (the popup closed before the handshake finished),
|
|
82
|
+
`auth/unauthorized-domain`, `auth/operation-not-allowed`, `auth/internal-error`.
|
|
83
|
+
|
|
84
|
+
Design record: [`docs/plan/spec-firebase-auth.md`](../plan/spec-firebase-auth.md).
|
|
@@ -97,6 +97,6 @@ JWT rolling keys and OAuth2 provider setup are documented in [`docs/appGenerated
|
|
|
97
97
|
|
|
98
98
|
## Client-facing API behaviour
|
|
99
99
|
|
|
100
|
-
Pagination, search and the response envelope: [`docs/apiUsage.md`](../apiUsage.md).
|
|
100
|
+
Pagination, search and the response envelope: [`docs/features/apiUsage.md`](../features/apiUsage.md).
|
|
101
101
|
|
|
102
102
|
Filter DSL for `find` / `count`: [`docs/features/filterOperators.md`](../features/filterOperators.md).
|
|
@@ -91,7 +91,7 @@ Guide: [`docs/features/auditFields.md`](../features/auditFields.md).
|
|
|
91
91
|
|
|
92
92
|
`src/generators/middlewares/joinWhitelistRegistry.generator.ts` emits a static entity → allowed-joins map consumed by `JoinWhitelistMiddleware.ts`. Populated from `x-documentConfig.restApi.joinWhitelist`; auto-filled by `jsonSchemaForeignKeys.ts` when unset. Controllers with a whitelist get `@Middlewares(JoinWhitelistMiddleware.middleware("<DocName>"))`.
|
|
93
93
|
|
|
94
|
-
See [`docs/features/joinWhitelist.md`](../features/joinWhitelist.md) and [`docs/ForeignKey.md`](../ForeignKey.md).
|
|
94
|
+
See [`docs/features/joinWhitelist.md`](../features/joinWhitelist.md) and [`docs/features/ForeignKey.md`](../features/ForeignKey.md).
|
|
95
95
|
|
|
96
96
|
## RBAC
|
|
97
97
|
|
|
@@ -5,8 +5,7 @@ Self-service account deletion for generated apps: `POST /api/auth/delete-account
|
|
|
5
5
|
keep their required foreign keys — and its credentials and personal data are erased.
|
|
6
6
|
|
|
7
7
|
This covers the identity domain only. Business rows, uploaded objects and third-party identities
|
|
8
|
-
(Firebase, etc.) belong to the application.
|
|
9
|
-
split.
|
|
8
|
+
(Firebase, etc.) belong to the application.
|
|
10
9
|
|
|
11
10
|
## Configuration
|
|
12
11
|
|
|
@@ -9,7 +9,7 @@ Generated apps declare `createdBy` / `createdAt` / `updatedBy` / `updatedAt` in
|
|
|
9
9
|
but nothing ever writes them — `grep -rn "createdBy\|updatedBy" src/` in the generator is empty.
|
|
10
10
|
The columns exist in the entities and stay NULL forever.
|
|
11
11
|
|
|
12
|
-
Consequences seen in
|
|
12
|
+
Consequences seen in a production deployment:
|
|
13
13
|
|
|
14
14
|
- A custom controller checking `findOne({ _id, createdBy: request.user._id })` never matches → `404` on `DELETE /api/job/{id}`.
|
|
15
15
|
- Timeline ordering bugs, because `createdAt` is also never written.
|
|
@@ -251,7 +251,7 @@ schema — a keyword would otherwise become a literal string default.
|
|
|
251
251
|
|
|
252
252
|
- Soft delete.
|
|
253
253
|
- Backfilling existing NULL rows.
|
|
254
|
-
-
|
|
254
|
+
- An app whose ownership column points at a profile row rather than at `User`.
|
|
255
255
|
- Extending `useUserSchema: false` into a fully custom account model. Today `User.json` is copied from the
|
|
256
256
|
templates unconditionally and `localAuth` requires `useUserSchema: true`, so a custom identity schema is
|
|
257
257
|
not reachable yet; `x-vexData: "userId"` is the forward-compatible hook for it.
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# v0.8.4
|
|
2
|
+
|
|
3
|
+
## Account deletion (tombstone)
|
|
4
|
+
|
|
5
|
+
Generated apps now get self-service account deletion: `POST /api/auth/delete-account` and a
|
|
6
|
+
`/delete_account` page, on by default.
|
|
7
|
+
|
|
8
|
+
The account is **soft-deleted**, not erased. The row survives so business tables can keep their
|
|
9
|
+
required foreign keys — a hard delete would orphan every `Job`, `ChatMessage` and `UserReport`
|
|
10
|
+
pointing at it — while credentials and personal data are removed.
|
|
11
|
+
|
|
12
|
+
| Step | Effect |
|
|
13
|
+
|---|---|
|
|
14
|
+
| Clear credentials | `UserAuthProfiles`, `UserRole`, `Session` rows for the user are hard-deleted |
|
|
15
|
+
| Tombstone last | `deleted: true`, `email` → NULL, `name` → `"Deleted user"`, `locale` / `profileErrors` → NULL, `active` → false |
|
|
16
|
+
|
|
17
|
+
Credentials are removed **before** the tombstone on purpose. Tombstoning first would leave the OAuth
|
|
18
|
+
path able to resolve the account through `provider` / `oauthId`, i.e. a deleted user could log back
|
|
19
|
+
into their own tombstone. Marker last also means a mid-flight failure leaves a live account that can
|
|
20
|
+
simply be retried.
|
|
21
|
+
|
|
22
|
+
`email` becomes `NULL`, never `""`: `User` declares a unique index on it, so a second deletion would
|
|
23
|
+
collide on the empty string, and the same address must be able to register a fresh account
|
|
24
|
+
immediately.
|
|
25
|
+
|
|
26
|
+
Deletion is idempotent — a repeat call changes nothing.
|
|
27
|
+
|
|
28
|
+
## Soft delete: `x-vexData: "softDelete"`
|
|
29
|
+
|
|
30
|
+
Soft delete is a general, opt-in schema feature, not a hard-coded user concept. Tag one boolean
|
|
31
|
+
property:
|
|
32
|
+
|
|
33
|
+
```jsonc
|
|
34
|
+
"deleted": { "type": "boolean", "default": false, "x-vexData": "softDelete" }
|
|
35
|
+
// and list it in the root "required" array
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- **Not client-writable.** The marker is omitted from the generated request body (`PayloadUser`), so
|
|
39
|
+
a client cannot soft-delete, resurrect or pre-tombstone a row through the CRUD API.
|
|
40
|
+
- **Hidden by default.** The adapters add `marker IS NOT TRUE` (`$ne: true` on Mongo) to every read
|
|
41
|
+
and write filter. No call-site changes.
|
|
42
|
+
- **No new columns.** `softDelete(id, data?)` writes the marker through the normal update-phase
|
|
43
|
+
machinery, so `updatedAt` / `updatedBy` record who deleted the row and when. There is no
|
|
44
|
+
`deletedAt` / `deletedBy`.
|
|
45
|
+
- **Required + defaulted.** The marker must be `boolean`, `default: false` and `required`, producing
|
|
46
|
+
`boolean NOT NULL DEFAULT false`. A nullable marker would make the hide-filter drop every row
|
|
47
|
+
written before the column existed.
|
|
48
|
+
|
|
49
|
+
Internal callers use dedicated repository methods, never a filter key:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
softDelete(id, data?) // write the marker + redaction in one update
|
|
53
|
+
findOneWithDeleted(filter, join, select) // skip ONLY the soft-delete term; ownership still applies
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A soft-delete key inside `Filter<T>` was rejected deliberately: `Filter` is the shape of every HTTP
|
|
57
|
+
`filter` body, so it would have been a client-side bypass.
|
|
58
|
+
|
|
59
|
+
The hide term is **not** applied to relation loading — which is why the marker is a plain column and
|
|
60
|
+
not TypeORM's `@DeleteDateColumn`, whose relation-nulling would break retained conversations
|
|
61
|
+
rendering "Deleted user".
|
|
62
|
+
|
|
63
|
+
## Tokens of deleted accounts are rejected
|
|
64
|
+
|
|
65
|
+
`Authentication.middleware` verified the JWT signature and nothing else, so a deleted user's
|
|
66
|
+
unexpired access token kept working for the rest of its lifetime. A generated `AccountStateGuard`
|
|
67
|
+
now closes that gap.
|
|
68
|
+
|
|
69
|
+
It reads the marker **value** rather than relying on the row being hidden, so the answer holds even
|
|
70
|
+
under `app.showSoftDeleted`, where a visibility-based check would call every tombstone alive. It
|
|
71
|
+
treats a missing marker as live (`!== true`), matching the adapters.
|
|
72
|
+
|
|
73
|
+
Every other auth path was already fail-closed: refresh and the OAuth exchange look the user up
|
|
74
|
+
through a soft-filtered read, local login compares an email that is now NULL, and the OAuth callback
|
|
75
|
+
cannot re-bind because the profile rows are gone.
|
|
76
|
+
|
|
77
|
+
## Config
|
|
78
|
+
|
|
79
|
+
```jsonc
|
|
80
|
+
{
|
|
81
|
+
"app": { "showSoftDeleted": false },
|
|
82
|
+
"auth": { "deleteAccount": true }
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
- `auth.deleteAccount` — **default true** (opt-out). Also requires auth to be enabled: a deletion
|
|
87
|
+
endpoint that cannot authenticate a caller could only delete the wrong account. When false, no
|
|
88
|
+
endpoint, no service, no page.
|
|
89
|
+
- `app.showSoftDeleted` — **default false**. Lifts the adapter filter app-wide, making tombstones
|
|
90
|
+
visible and writable again. It warns on every generation run, because it is a blunt instrument: it
|
|
91
|
+
applies to every entity, including ones added later.
|
|
92
|
+
|
|
93
|
+
Both are read with `??`, so an explicit `false` is never swallowed.
|
|
94
|
+
|
|
95
|
+
## The `/delete_account` page
|
|
96
|
+
|
|
97
|
+
Served from `LoginUI` rather than as a static file — `express.static("public")` would expose
|
|
98
|
+
`public/delete_account.html` at `/delete_account.html`, not at the route a store listing points at.
|
|
99
|
+
Linked from `/`.
|
|
100
|
+
|
|
101
|
+
`LoginUIConfig.deleteAccount` is optional and defaults to true, because an app's `server.ts` is
|
|
102
|
+
generated once and is not overwritten on later runs; a required field would stop such a project from
|
|
103
|
+
compiling.
|
|
104
|
+
|
|
105
|
+
The client clears its stored tokens on success — the account is gone the moment the tombstone is
|
|
106
|
+
written, so keeping a token the server now rejects would only produce confusing 401s.
|
|
107
|
+
|
|
108
|
+
## Behaviour changes
|
|
109
|
+
|
|
110
|
+
- **Every authenticated request costs one extra indexed read** of the identity row when the identity
|
|
111
|
+
document is soft-deletable. Projects with no soft-delete marker are unaffected — the guard is
|
|
112
|
+
emitted as a no-op there.
|
|
113
|
+
- **A request carrying a soft-delete marker is rejected with `400 Invalid Request Body`**, matching
|
|
114
|
+
the existing `throw-on-extras` contract for other server-managed fields.
|
|
115
|
+
|
|
116
|
+
## After upgrading
|
|
117
|
+
|
|
118
|
+
Re-run the generator. Then:
|
|
119
|
+
|
|
120
|
+
1. **Add the column.** `useUserSchema` apps get `User.deleted` merged in automatically.
|
|
121
|
+
`SQL_SYNCHRONIZE=true` covers development; production needs
|
|
122
|
+
`ALTER TABLE "user" ADD COLUMN "deleted" boolean NOT NULL DEFAULT false`.
|
|
123
|
+
2. **Check `allowOverwrite: false`.** An app that pinned `UserModel.gen.ts` / `User.gen.ts` must add
|
|
124
|
+
the column by hand, or clear those `.vex/meta.json` entries, or the SQL column will not exist.
|
|
125
|
+
3. **Business rows and uploaded objects are the app's job.** This release covers the identity domain
|
|
126
|
+
only. Third-party identities too: vex cannot delete a Firebase account — capture the provider uid
|
|
127
|
+
*before* calling the service.
|
|
128
|
+
4. **To disable it entirely:** `"auth": { "deleteAccount": false }`.
|
|
129
|
+
|
|
130
|
+
Guides: [`docs/features/accountDeletion.md`](../features/accountDeletion.md),
|
|
131
|
+
[`docs/vexJsonSchema.md`](../vexJsonSchema.md).
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# v0.8.5
|
|
2
|
+
|
|
3
|
+
## Breaking: the identity key is renamed, and now enforced
|
|
4
|
+
|
|
5
|
+
`UserAuthProfiles.oauthId` is **`providerUserId`**, and `(provider, providerUserId)` is a **composite
|
|
6
|
+
unique index**. The value never changed — it is the subject within `provider`'s namespace — but the old
|
|
7
|
+
name claimed a protocol the field does not require, and nothing stopped two rows claiming one identity.
|
|
8
|
+
|
|
9
|
+
Re-run the generator (migration `v0.8.5` rewrites the schema, and any `uniqueIndex` entry naming the old
|
|
10
|
+
field), then migrate the database:
|
|
11
|
+
|
|
12
|
+
```sql
|
|
13
|
+
ALTER TABLE "userauthprofiles" RENAME COLUMN "oauthId" TO "providerUserId";
|
|
14
|
+
ALTER TABLE "userauthprofiles" ADD CONSTRAINT "unique_provider_providerUserId"
|
|
15
|
+
UNIQUE ("provider", "providerUserId");
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Look for existing duplicates before adding the constraint:
|
|
19
|
+
|
|
20
|
+
```sql
|
|
21
|
+
SELECT provider, "providerUserId", COUNT(*) FROM "userauthprofiles"
|
|
22
|
+
GROUP BY 1,2 HAVING COUNT(*) > 1;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`SQL_SYNCHRONIZE=true` covers development. App code that reads `oauthId` must be updated.
|
|
26
|
+
|
|
27
|
+
## New: Firebase as a sign-in option
|
|
28
|
+
|
|
29
|
+
`auth.firebase: true` generates `POST /api/auth/firebase` and a button on the generated `/login` page.
|
|
30
|
+
The endpoint takes a Firebase ID token and answers with the vex token pair:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
POST /api/auth/firebase { "idToken": "<Firebase ID token>" }
|
|
34
|
+
200 { "result": { accessToken, accessTokenIndex, refreshToken, refreshTokenIndex, isNewUser } }
|
|
35
|
+
503 no usable service account 401 invalid or expired token
|
|
36
|
+
400 the sign-in has no upstream IdP 409 the sign-in carries no email
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The identity written is the **upstream** IdP's — `("google", <Google sub>)` for a Google sign-in, the
|
|
40
|
+
same pair `passport-google-oauth20` writes, so both doors resolve to one `User` row.
|
|
41
|
+
|
|
42
|
+
```jsonc
|
|
43
|
+
"auth": { "firebase": true }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
That boolean is the only switch. Everything else is environment. Four required values, under the names a
|
|
47
|
+
deployment already has; two variables earlier drafts carried are gone because nothing reads them
|
|
48
|
+
(`FIREBASE_APP_ID` — Firebase Auth takes no appId — and a file-path alternative to the service account).
|
|
49
|
+
|
|
50
|
+
| Variable | Used by |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `FIREBASE_SERVICE_ACCOUNT_JSON` | server — `firebase-admin` |
|
|
53
|
+
| `FIREBASE_WEB_API_KEY`, `FIREBASE_WEB_AUTH_DOMAIN`, `FIREBASE_WEB_PROJECT_ID` | login page — public, by design |
|
|
54
|
+
| `FIREBASE_PROVIDERS` | optional; which buttons `/login` renders; default `google` |
|
|
55
|
+
|
|
56
|
+
Design record, including the identity rules and the reasons behind them:
|
|
57
|
+
[`docs/plan/spec-firebase-auth.md`](../plan/spec-firebase-auth.md).
|
|
58
|
+
|
|
59
|
+
## Also fixed
|
|
60
|
+
|
|
61
|
+
- **A project with `localAuth: false` and any other sign-in path generated a controller that did not
|
|
62
|
+
compile** — `exchangeToken` / `refreshToken` call `this.userRepo`, which was only emitted when
|
|
63
|
+
`localAuth` was on. The getter is now emitted whenever auth is enabled. Reachable before this release
|
|
64
|
+
with `oauthProviders` alone; the Firebase-only configuration is the same shape.
|
|
65
|
+
|
|
66
|
+
## After upgrading
|
|
67
|
+
|
|
68
|
+
1. **`npm install`** — `firebase-admin` is a dependency of the generated app (the browser SDK is loaded
|
|
69
|
+
from gstatic by the login page, so the `firebase` package is not needed).
|
|
70
|
+
2. **Re-run `vex`.**
|
|
71
|
+
3. **Run the SQL above** if your identity table is older than this release.
|
|
72
|
+
4. **Set the environment** — the service account, plus the three public values from one *Web* app
|
|
73
|
+
registration in the same Firebase project. Paste the downloaded key file into
|
|
74
|
+
`FIREBASE_SERVICE_ACCOUNT_JSON` as-is: its fields are snake_case (`project_id`, `private_key`,
|
|
75
|
+
`client_email`) and that is what the loader expects.
|
|
76
|
+
5. **Turn it on** with `"auth": { "firebase": true }`, then re-run `vex`.
|
|
77
|
+
6. **Open `/login`.** The button posts to `/api/auth/firebase`; a failed sign-in names the server-side
|
|
78
|
+
configuration problem it can see (missing variables, an unstartable provider name).
|
|
79
|
+
|
|
80
|
+
Notes:
|
|
81
|
+
|
|
82
|
+
- The login page loads the **modular** Firebase SDK as ES modules from gstatic (pinned version), the
|
|
83
|
+
same way the app's own web sign-in does, and preloads it on page load. That needs `www.gstatic.com` in
|
|
84
|
+
`script-src`, plus `connect-src` for the token endpoints and `frame-src` for the project's auth domain
|
|
85
|
+
— the generated page sets all three itself, so an app-wide `helmet` CSP does not have to change.
|
|
86
|
+
- The glue is **inlined into the generated page**, not served from `public/js/`. `public/**` is a
|
|
87
|
+
copy-once template, and an earlier draft of this feature put `public/js/firebaseauth.js` there — so a
|
|
88
|
+
project that ran that draft keeps a compat-era file while its page moved on, and the page fails with
|
|
89
|
+
`Firebase sign-in is not configured: window.undefined is missing`. **Delete
|
|
90
|
+
`public/js/firebaseauth.js`** from any project generated from that draft; nothing references it any
|
|
91
|
+
more. (Same for a stale `/js/firebase/*` route, if you carried one.)
|
|
92
|
+
- The login page overrides `Cross-Origin-Opener-Policy` to `same-origin-allow-popups`. helmet's default
|
|
93
|
+
(`same-origin`) nulls `window.opener` inside a cross-origin popup, which is the channel the Firebase
|
|
94
|
+
handler reports on, and the SDK then reports **`auth/popup-closed-by-user`** — a message that points at
|
|
95
|
+
the user and the network, never at the header that actually caused it. If you proxy or re-render the
|
|
96
|
+
login page yourself, keep this header.
|
|
97
|
+
- `LoginUI.gen.ts` and `FirebaseAuthUI.gen.ts` are regenerated even when `auth.firebase` is false; the
|
|
98
|
+
wiring module exports `undefined` and the page renders no Firebase button.
|
|
@@ -8,7 +8,7 @@ Branch: TBD
|
|
|
8
8
|
|
|
9
9
|
`createdBy` / `createdAt` 这类审计字段在生成的应用里**静默留下 NULL**,且没有任何信号。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
生产项目的实测现场:
|
|
12
12
|
|
|
13
13
|
- 23/24 个 schema 声明了 `createdBy` / `updatedBy`(`onCreateUserId` / `onUpdateUserId`)
|
|
14
14
|
- 只有 `User` 一个声明了 `dataIsolation`
|
|
@@ -67,7 +67,7 @@ if (useAuth) {
|
|
|
67
67
|
|
|
68
68
|
改为 fail-loud 即推翻此契约,文档必须同步。
|
|
69
69
|
|
|
70
|
-
### 2.4
|
|
70
|
+
### 2.4 触发路径证明(生产项目实测)
|
|
71
71
|
|
|
72
72
|
```
|
|
73
73
|
$ grep -rln "DataIsolationContext.middleware" src/system/_controllers/ | wc -l
|
|
@@ -211,7 +211,7 @@ UserContext.run(tokenData, () => next());
|
|
|
211
211
|
- `:55` 的 `DataIsolationContext` 可选 import 删除
|
|
212
212
|
- 不再生成独立的上下文中间件 —— `UserContext` 从 middleware 降级为 helper 模块(只剩 `run()` / `getStore()` / `userId`)
|
|
213
213
|
|
|
214
|
-
**为什么这是从构造上消除挂载门**:`Authentication.middleware` 本来就挂在每个 `useAuth` 的 controller 上(生成 18 个 +
|
|
214
|
+
**为什么这是从构造上消除挂载门**:`Authentication.middleware` 本来就挂在每个 `useAuth` 的 controller 上(生成 18 个 + 应用手写 17 个里的 14 个)。没有第二处需要记得挂的装饰器,就没有「忘了挂」这一态。
|
|
215
215
|
|
|
216
216
|
### 4.4 Adapter 强制规则
|
|
217
217
|
|
|
@@ -338,9 +338,9 @@ Mongoose `replace` 与其余三者行为不一致。本 spec 接受,但要求
|
|
|
338
338
|
|
|
339
339
|
**代价(明确接受)**:**没有逃生口**。任何处于请求链之外的写(seed、后台 job、tsoa 注册路径)都无法声明身份,只能硬失败或静默 NULL。
|
|
340
340
|
|
|
341
|
-
|
|
341
|
+
**影响面(生产项目实测)**:`VexDb.getRepository(...)` 构造点 79 处,其中写路径 19 处(4 处直连写 + 15 处 `this.repo`)。选 ALS 路线意味着这 79 处**零改动**。
|
|
342
342
|
|
|
343
|
-
|
|
343
|
+
**已识别的硬冲突**:某应用的注册路径在**无 auth** 的 controller 里 create `User`:
|
|
344
344
|
|
|
345
345
|
| 位置 | 装饰器 |
|
|
346
346
|
|---|---|
|
|
@@ -391,11 +391,11 @@ const user = await this.userRepo.create({ name: email.split("@")[0], email, acti
|
|
|
391
391
|
|
|
392
392
|
### 6.1 注册路径(高)
|
|
393
393
|
|
|
394
|
-
见 D2
|
|
394
|
+
见 D2。当前该应用安全,但依赖「`User` 没有 `createdBy`」这一巧合。必须在 D2 的 A/B/C 中做出选择后才能认为风险闭环。
|
|
395
395
|
|
|
396
396
|
### 6.2 请求链外的写入(中)
|
|
397
397
|
|
|
398
|
-
`src/services/*`
|
|
398
|
+
`src/services/*` 中的写路径无请求上下文。实测:
|
|
399
399
|
|
|
400
400
|
| 位置 | 写入 | 该实体是否有 `onCreateUserId` |
|
|
401
401
|
|---|---|---|
|
|
@@ -445,9 +445,9 @@ const user = await this.userRepo.create({ name: email.split("@")[0], email, acti
|
|
|
445
445
|
| 删除生成的 `@Middlewares(DataIsolationContext.middleware)` | 破坏性(生成物) | 下游需重新 `vex`;旧的 `DataIsolationContext.gen.ts` 会被 `cleanupStaleFiles()` 清理 |
|
|
446
446
|
| `pipeline` 生成 `UserContext.gen.ts` | 新增 | — |
|
|
447
447
|
| 数据隔离功能 | 无变化 | 覆盖面顺带扩大(所有 authed controller) |
|
|
448
|
-
| **数据隔离第一次真正生效** | **破坏性(下游可见)** | `entityIsolation` 里的实体,此前若其 controller 没挂中间件就不过滤;改后任何 authed controller 访问它都会过滤。`mergeFilter` 是 `{ ...mapped, ...ownership }`,**ownership 覆盖调用方 filter 的 `_id`** → 按 id 查/改的接口会静默变成「操作自己那一行」。**这是各 app 自己的接口问题,修复不在本卡范围**
|
|
448
|
+
| **数据隔离第一次真正生效** | **破坏性(下游可见)** | `entityIsolation` 里的实体,此前若其 controller 没挂中间件就不过滤;改后任何 authed controller 访问它都会过滤。`mergeFilter` 是 `{ ...mapped, ...ownership }`,**ownership 覆盖调用方 filter 的 `_id`** → 按 id 查/改的接口会静默变成「操作自己那一行」。**这是各 app 自己的接口问题,修复不在本卡范围** |
|
|
449
449
|
|
|
450
|
-
**迁移**:下游跑一次 `vex`。历史 NULL 行**不会**被回填 —— 需要各应用自行决定值(`createdBy`
|
|
450
|
+
**迁移**:下游跑一次 `vex`。历史 NULL 行**不会**被回填 —— 需要各应用自行决定值(`createdBy` 有些可由关系推导,有些应用的 owner 是 profile 行而 `createdBy` 语义是 `User`,推不出来)。
|
|
451
451
|
|
|
452
452
|
## 8. 测试计划
|
|
453
453
|
|
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
File without changes
|
|
File without changes
|