@molecule/api-resource-user 1.5.1 → 1.5.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.
- package/README.md +117 -21
- package/dist/authorization.d.ts +56 -6
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +95 -5
- package/dist/authorization.js.map +1 -1
- package/dist/handlers/create.d.ts.map +1 -1
- package/dist/handlers/create.js +6 -2
- package/dist/handlers/create.js.map +1 -1
- package/dist/index.d.ts +40 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -9
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts +5 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -1
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-10-
|
|
6
|
+
Generated: 2026-10-16T15:44:04.216Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -14,12 +14,35 @@ Generated: 2026-10-16T06:31:34.682Z
|
|
|
14
14
|
|
|
15
15
|
The `user` resource types, schema, and definition.
|
|
16
16
|
|
|
17
|
+
**This package owns TWO tables, and the key that joins them is the user's own id.**
|
|
18
|
+
|
|
19
|
+
- `users` — {@link Props}: `id`, `username`, `name`, `email`, `emailVerified`, `avatar`,
|
|
20
|
+
`bio`, `twoFactorEnabled`, the `oauth*` and `plan*` columns. **There is no password column
|
|
21
|
+
here.**
|
|
22
|
+
- `usersSecrets` — {@link SecretProps}: `passwordHash`, `passwordResetToken` (and
|
|
23
|
+
`passwordResetTokenAt`), `twoFactorSecret` / `pendingTwoFactorSecret`, `lastTwoFactorTimeStep`.
|
|
24
|
+
|
|
25
|
+
**`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
|
|
26
|
+
declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces the pairing: a row
|
|
27
|
+
written under another id is never found again — login answers "invalid credentials" while
|
|
28
|
+
`GET /api/users/me` (which reads `users` only) still answers 200. A hand-written signup writes
|
|
29
|
+
both rows from one id:
|
|
30
|
+
`const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
|
|
31
|
+
|
|
32
|
+
Prefer not to hand-write any of that: the handlers this package ships already do it —
|
|
33
|
+
`handlers.create` (signup: writes both rows, hashes with `@molecule/api-password`, mints the
|
|
34
|
+
session device), `handlers.logIn` (login: reads `usersSecrets` by the user's id and compares the
|
|
35
|
+
hash), `handlers.updatePassword`, and `handlers.forgotPassword` / `handlers.resetPassword` (the
|
|
36
|
+
emailed-token reset). To read or write one secret yourself, use the abstract datastore on the
|
|
37
|
+
same key — `findById('usersSecrets', userId)`, or `${tableName}Secrets` when the resource
|
|
38
|
+
carries a custom `tableName` — never SQL.
|
|
39
|
+
|
|
17
40
|
## Quick Start
|
|
18
41
|
|
|
19
42
|
```ts
|
|
20
43
|
// Extend safely: a display field in Props, a secret in SecretProps.
|
|
21
44
|
// propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
22
|
-
// secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only,
|
|
45
|
+
// secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
|
23
46
|
|
|
24
47
|
// A custom handler returns SAFE props — never the secrets row.
|
|
25
48
|
router.get('/me/timezone', async (req, res) => {
|
|
@@ -83,7 +106,8 @@ interface UserRequestHandlerMap {
|
|
|
83
106
|
|
|
84
107
|
#### `Props`
|
|
85
108
|
|
|
86
|
-
User props type inferred from schema
|
|
109
|
+
User props type inferred from schema — the row shape of the `users` table, which holds no
|
|
110
|
+
password.
|
|
87
111
|
|
|
88
112
|
```typescript
|
|
89
113
|
type Props = z.infer<typeof propsSchema>
|
|
@@ -91,7 +115,7 @@ type Props = z.infer<typeof propsSchema>
|
|
|
91
115
|
|
|
92
116
|
#### `SecretProps`
|
|
93
117
|
|
|
94
|
-
Secret
|
|
118
|
+
Secret props type — the row shape of the `usersSecrets` table, whose `id` is the user's id.
|
|
95
119
|
|
|
96
120
|
```typescript
|
|
97
121
|
type SecretProps = z.infer<typeof secretPropsSchema>
|
|
@@ -344,7 +368,8 @@ const propsSchema: z.ZodObject<
|
|
|
344
368
|
|
|
345
369
|
#### `secretPropsSchema`
|
|
346
370
|
|
|
347
|
-
Secret properties stored in
|
|
371
|
+
Secret properties stored in the separate `usersSecrets` table, keyed by `id` = the user's id
|
|
372
|
+
(the value of `users.id`, never a fresh uuid).
|
|
348
373
|
|
|
349
374
|
```typescript
|
|
350
375
|
const secretPropsSchema: z.ZodObject<
|
|
@@ -604,9 +629,57 @@ subsequent requests; only these rare revocation events pay a brief re-check.
|
|
|
604
629
|
function invalidateAllDeviceExistsCache(): void
|
|
605
630
|
```
|
|
606
631
|
|
|
632
|
+
##### `authorization.ALLOW_COOKIE_SESSION_LOCALS_KEY`
|
|
633
|
+
|
|
634
|
+
`res.locals` key carrying THIS request's cookie-session policy. {@link verifyMiddleware}
|
|
635
|
+
writes it from its `allowCookieSession` option; {@link set} reads it. When the value is
|
|
636
|
+
`false` the request arrived through a mount that authenticates by `Authorization` header
|
|
637
|
+
only, so `set()` must not hand the client the `token` / `sessionId` / `mol_auth` cookies
|
|
638
|
+
either: a cookie written here authenticates that same client on its NEXT request (an HTTP
|
|
639
|
+
test runner's cookie jar, `curl -b`, a browser) through any mount that does accept one,
|
|
640
|
+
which is how a suite step called "no auth" comes back 200.
|
|
641
|
+
|
|
642
|
+
Exported so a custom auth middleware can declare the same policy for the requests it
|
|
643
|
+
handles, and so tests can assert the key rather than a string literal.
|
|
644
|
+
|
|
645
|
+
```typescript
|
|
646
|
+
const ALLOW_COOKIE_SESSION_LOCALS_KEY: 'allowCookieSession'
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
##### `authorization.AUTH_SESSION_SOURCE_LOCALS_KEY`
|
|
650
|
+
|
|
651
|
+
`res.locals` key carrying HOW this request's session was resolved — `'header'` when
|
|
652
|
+
the `Authorization` header named the token, `'cookie'` when only the `token` cookie
|
|
653
|
+
did. {@link verifyMiddleware} writes it alongside `res.locals.session`.
|
|
654
|
+
|
|
655
|
+
A mount with `allowCookieSession: false` reads it to drop a session an EARLIER, laxer
|
|
656
|
+
mount already resolved out of the cookie (the scaffold mounts `verifyMiddleware` twice,
|
|
657
|
+
and the first one runs for every `/api` request). A session resolved from the header is
|
|
658
|
+
never dropped: that client sent its credentials, which is exactly what a token-only API
|
|
659
|
+
accepts.
|
|
660
|
+
|
|
661
|
+
```typescript
|
|
662
|
+
const AUTH_SESSION_SOURCE_LOCALS_KEY: 'authSessionSource'
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
##### `authorization.AuthSessionSource`
|
|
666
|
+
|
|
667
|
+
How {@link verifyMiddleware} resolved a request's session. See {@link AUTH_SESSION_SOURCE_LOCALS_KEY}.
|
|
668
|
+
|
|
669
|
+
```typescript
|
|
670
|
+
type AuthSessionSource = 'header' | 'cookie'
|
|
671
|
+
```
|
|
672
|
+
|
|
607
673
|
##### `authorization.set(_req, res, session)`
|
|
608
674
|
|
|
609
|
-
Set authorization headers and cookie for a session.
|
|
675
|
+
Set authorization headers and cookie for a session, and RETURN the signed token.
|
|
676
|
+
|
|
677
|
+
To put a session token in a JSON response BODY — an API whose clients send
|
|
678
|
+
`Authorization: Token <jwt>` — call this and use its return value. Do NOT sign a
|
|
679
|
+
second token with another key or algorithm: `verifyMiddleware` verifies with the app's
|
|
680
|
+
bonded `@molecule/api-jwt` provider, so a self-signed one answers 401 on the very next
|
|
681
|
+
request. Mount `verifyMiddleware({ allowCookieSession: false })` in front of the routes
|
|
682
|
+
that sign users in and the client gets the token without any session cookie.
|
|
610
683
|
|
|
611
684
|
The token is bound to `session.deviceId`, and `verifyMiddleware` rejects any session whose
|
|
612
685
|
device row does not exist (that is how signing out revokes a session). Mint the id with
|
|
@@ -614,6 +687,14 @@ device row does not exist (that is how signing out revokes a session). Mint the
|
|
|
614
687
|
(register, login, OAuth, password reset), as `handlers/logIn.ts` does: a placeholder
|
|
615
688
|
(`'unknown'`, `''`, the user's id) yields a token that every later request answers 401.
|
|
616
689
|
|
|
690
|
+
Always sets the `Authorization` response header. Writes the session cookies (the httpOnly
|
|
691
|
+
`token` and `sessionId`, plus the readable `mol_auth` presence hint) UNLESS the request's
|
|
692
|
+
cookie-session policy is off — see {@link ALLOW_COOKIE_SESSION_LOCALS_KEY}, written by
|
|
693
|
+
{@link verifyMiddleware}. A token-only API (`allowCookieSession: false`) gets the header
|
|
694
|
+
and no cookies, so its clients cannot drift into a cookie session.
|
|
695
|
+
|
|
696
|
+
_(description truncated — read the full text in `node_modules/@molecule/api-resource-user/dist/authorization.d.ts`.)_
|
|
697
|
+
|
|
617
698
|
```typescript
|
|
618
699
|
function set(
|
|
619
700
|
_req: MoleculeRequest,
|
|
@@ -656,11 +737,16 @@ interface VerifyMiddlewareOptions {
|
|
|
656
737
|
*/
|
|
657
738
|
shouldRefreshSession?: (session: Session, req: MoleculeRequest) => boolean | Promise<boolean>
|
|
658
739
|
/**
|
|
659
|
-
*
|
|
740
|
+
* Whether the `token` cookie is a session on this mount, in BOTH directions.
|
|
660
741
|
* Defaults to `true` (browser clients sign in once and every page request carries
|
|
661
|
-
* the cookie).
|
|
662
|
-
*
|
|
663
|
-
*
|
|
742
|
+
* the cookie).
|
|
743
|
+
*
|
|
744
|
+
* Pass `false` for a token-only JSON API. Then the cookie is not a credential here:
|
|
745
|
+
* the middleware does not resolve a session from it (and drops one an earlier, laxer
|
|
746
|
+
* mount already resolved from it), and {@link set} does not write it either — so a
|
|
747
|
+
* client that keeps a cookie jar (an HTTP test runner, `curl -b`) never picks up a
|
|
748
|
+
* session it should not have, and stops answering 200 on the step its spec calls
|
|
749
|
+
* "no auth".
|
|
664
750
|
*/
|
|
665
751
|
allowCookieSession?: boolean
|
|
666
752
|
}
|
|
@@ -669,7 +755,7 @@ interface VerifyMiddlewareOptions {
|
|
|
669
755
|
##### `authorization.verifyMiddleware(options)`
|
|
670
756
|
|
|
671
757
|
Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
672
|
-
Falls back to cookie-based session for browser clients unless `allowCookieSession` is `false
|
|
758
|
+
Falls back to cookie-based session for browser clients unless `allowCookieSession` is `false` — which also stops `set()` writing the session cookie for this request. Auto-refreshes tokens older than `JWT_REFRESH_TIME`.
|
|
673
759
|
|
|
674
760
|
```typescript
|
|
675
761
|
function verifyMiddleware(options?: VerifyMiddlewareOptions): MoleculeRequestHandler
|
|
@@ -1545,7 +1631,8 @@ Re-exported as a namespace — reach every member below through it (e.g. `types.
|
|
|
1545
1631
|
|
|
1546
1632
|
##### `types.Props`
|
|
1547
1633
|
|
|
1548
|
-
User props type inferred from schema
|
|
1634
|
+
User props type inferred from schema — the row shape of the `users` table, which holds no
|
|
1635
|
+
password.
|
|
1549
1636
|
|
|
1550
1637
|
```typescript
|
|
1551
1638
|
type Props = z.infer<typeof propsSchema>
|
|
@@ -1553,7 +1640,7 @@ type Props = z.infer<typeof propsSchema>
|
|
|
1553
1640
|
|
|
1554
1641
|
##### `types.SecretProps`
|
|
1555
1642
|
|
|
1556
|
-
Secret
|
|
1643
|
+
Secret props type — the row shape of the `usersSecrets` table, whose `id` is the user's id.
|
|
1557
1644
|
|
|
1558
1645
|
```typescript
|
|
1559
1646
|
type SecretProps = z.infer<typeof secretPropsSchema>
|
|
@@ -1899,9 +1986,9 @@ The user record is split across TWO schemas — pick the right one or you leak c
|
|
|
1899
1986
|
`emailVerified`, `twoFactorEnabled`, plan). This is what handlers return and what lives
|
|
1900
1987
|
in the `users` table.
|
|
1901
1988
|
- **{@link SecretProps} (`secretPropsSchema`)** — SERVER-ONLY secrets: `passwordHash`, the
|
|
1902
|
-
TOTP `twoFactorSecret` (and its pending-setup value). Stored in
|
|
1903
|
-
and NEVER serialized to the client. Note the pair
|
|
1904
|
-
`Props`) vs `twoFactorSecret` (secret, in `SecretProps`).
|
|
1989
|
+
TOTP `twoFactorSecret` (and its pending-setup value). Stored in the SEPARATE `usersSecrets`
|
|
1990
|
+
table (keyed by `id` = the user's id) and NEVER serialized to the client. Note the pair
|
|
1991
|
+
`twoFactorEnabled` (safe boolean, in `Props`) vs `twoFactorSecret` (secret, in `SecretProps`).
|
|
1905
1992
|
|
|
1906
1993
|
When you extend the user, put a secret (token, hash, key, provider refresh token) in
|
|
1907
1994
|
`SecretProps`; put a display field in `Props`. **Never add a secret to `Props`, never
|
|
@@ -1927,11 +2014,20 @@ before calling a handler, or write the route yourself. A username keeps exactly
|
|
|
1927
2014
|
sent (letters, digits, `.`, `-`, `_`); anything else is answered 400
|
|
1928
2015
|
`user.error.usernameInvalid`, never rewritten.
|
|
1929
2016
|
|
|
1930
|
-
**A token-only JSON API:**
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
whose clients send the
|
|
2017
|
+
**A token-only JSON API:** by default the `token` cookie that login sets IS a session,
|
|
2018
|
+
and `authorization.set()` writes it on every sign-in — so a client that keeps a cookie
|
|
2019
|
+
jar (an HTTP test runner, `curl -b`) stays signed in on a request that sends no
|
|
2020
|
+
`Authorization` header, and gets 200 on the step the suite calls "no auth". Mount
|
|
2021
|
+
`verifyMiddleware({ allowCookieSession: false })` for an API whose clients send the
|
|
2022
|
+
header: that ONE option turns the cookie off in BOTH directions — the middleware no
|
|
2023
|
+
longer resolves a session from it (nor keeps one an earlier, laxer mount resolved), and
|
|
2024
|
+
`set()` stops writing `token` / `sessionId` / `mol_auth`, so even the sign-in response
|
|
2025
|
+
carries the `Authorization` header alone and the jar never fills. Set it on the mount in
|
|
2026
|
+
front of the routes that sign users in — the scaffold's `api/src/App/router.ts` — and
|
|
2027
|
+
check for a SECOND one: a request can pass several mounts (`api/src/server.ts`'s
|
|
2028
|
+
`preApiRouter` runs before `App/router.ts` and covers all of `/api`), the last one it
|
|
2029
|
+
passes sets the policy both halves read, and a laxer mount later in the chain cannot
|
|
2030
|
+
re-admit the cookie. If the app mounts two, mount it once instead.
|
|
1935
2031
|
|
|
1936
2032
|
**Revoking a session yourself:** the middleware caches "this device exists" for 10 s per
|
|
1937
2033
|
process, so a hand-written logout that deletes the `devices` row keeps authorizing that
|
package/dist/authorization.d.ts
CHANGED
|
@@ -90,7 +90,41 @@ export declare const invalidateDeviceExistsCache: (deviceId: string) => void;
|
|
|
90
90
|
*/
|
|
91
91
|
export declare const invalidateAllDeviceExistsCache: () => void;
|
|
92
92
|
/**
|
|
93
|
-
*
|
|
93
|
+
* `res.locals` key carrying THIS request's cookie-session policy. {@link verifyMiddleware}
|
|
94
|
+
* writes it from its `allowCookieSession` option; {@link set} reads it. When the value is
|
|
95
|
+
* `false` the request arrived through a mount that authenticates by `Authorization` header
|
|
96
|
+
* only, so `set()` must not hand the client the `token` / `sessionId` / `mol_auth` cookies
|
|
97
|
+
* either: a cookie written here authenticates that same client on its NEXT request (an HTTP
|
|
98
|
+
* test runner's cookie jar, `curl -b`, a browser) through any mount that does accept one,
|
|
99
|
+
* which is how a suite step called "no auth" comes back 200.
|
|
100
|
+
*
|
|
101
|
+
* Exported so a custom auth middleware can declare the same policy for the requests it
|
|
102
|
+
* handles, and so tests can assert the key rather than a string literal.
|
|
103
|
+
*/
|
|
104
|
+
export declare const ALLOW_COOKIE_SESSION_LOCALS_KEY = "allowCookieSession";
|
|
105
|
+
/**
|
|
106
|
+
* `res.locals` key carrying HOW this request's session was resolved — `'header'` when
|
|
107
|
+
* the `Authorization` header named the token, `'cookie'` when only the `token` cookie
|
|
108
|
+
* did. {@link verifyMiddleware} writes it alongside `res.locals.session`.
|
|
109
|
+
*
|
|
110
|
+
* A mount with `allowCookieSession: false` reads it to drop a session an EARLIER, laxer
|
|
111
|
+
* mount already resolved out of the cookie (the scaffold mounts `verifyMiddleware` twice,
|
|
112
|
+
* and the first one runs for every `/api` request). A session resolved from the header is
|
|
113
|
+
* never dropped: that client sent its credentials, which is exactly what a token-only API
|
|
114
|
+
* accepts.
|
|
115
|
+
*/
|
|
116
|
+
export declare const AUTH_SESSION_SOURCE_LOCALS_KEY = "authSessionSource";
|
|
117
|
+
/** How {@link verifyMiddleware} resolved a request's session. See {@link AUTH_SESSION_SOURCE_LOCALS_KEY}. */
|
|
118
|
+
export type AuthSessionSource = 'header' | 'cookie';
|
|
119
|
+
/**
|
|
120
|
+
* Set authorization headers and cookie for a session, and RETURN the signed token.
|
|
121
|
+
*
|
|
122
|
+
* To put a session token in a JSON response BODY — an API whose clients send
|
|
123
|
+
* `Authorization: Token <jwt>` — call this and use its return value. Do NOT sign a
|
|
124
|
+
* second token with another key or algorithm: `verifyMiddleware` verifies with the app's
|
|
125
|
+
* bonded `@molecule/api-jwt` provider, so a self-signed one answers 401 on the very next
|
|
126
|
+
* request. Mount `verifyMiddleware({ allowCookieSession: false })` in front of the routes
|
|
127
|
+
* that sign users in and the client gets the token without any session cookie.
|
|
94
128
|
*
|
|
95
129
|
* The token is bound to `session.deviceId`, and `verifyMiddleware` rejects any session whose
|
|
96
130
|
* device row does not exist (that is how signing out revokes a session). Mint the id with
|
|
@@ -98,6 +132,17 @@ export declare const invalidateAllDeviceExistsCache: () => void;
|
|
|
98
132
|
* (register, login, OAuth, password reset), as `handlers/logIn.ts` does: a placeholder
|
|
99
133
|
* (`'unknown'`, `''`, the user's id) yields a token that every later request answers 401.
|
|
100
134
|
*
|
|
135
|
+
* Always sets the `Authorization` response header. Writes the session cookies (the httpOnly
|
|
136
|
+
* `token` and `sessionId`, plus the readable `mol_auth` presence hint) UNLESS the request's
|
|
137
|
+
* cookie-session policy is off — see {@link ALLOW_COOKIE_SESSION_LOCALS_KEY}, written by
|
|
138
|
+
* {@link verifyMiddleware}. A token-only API (`allowCookieSession: false`) gets the header
|
|
139
|
+
* and no cookies, so its clients cannot drift into a cookie session.
|
|
140
|
+
*
|
|
141
|
+
* The policy is the MOUNT's, and the mount records it on every request it passes — including
|
|
142
|
+
* the sign-in request itself, which carries no token and therefore resolves no session. So a
|
|
143
|
+
* token-only API writes no cookie from the very first response: mount
|
|
144
|
+
* `verifyMiddleware({ allowCookieSession: false })` in front of the routes that sign users in.
|
|
145
|
+
*
|
|
101
146
|
* @param _req - The request object (unused; reserved for handler signature parity).
|
|
102
147
|
* @param res - The response object.
|
|
103
148
|
* @param session - The session.
|
|
@@ -122,17 +167,22 @@ export interface VerifyMiddlewareOptions {
|
|
|
122
167
|
*/
|
|
123
168
|
shouldRefreshSession?: (session: Session, req: MoleculeRequest) => boolean | Promise<boolean>;
|
|
124
169
|
/**
|
|
125
|
-
*
|
|
170
|
+
* Whether the `token` cookie is a session on this mount, in BOTH directions.
|
|
126
171
|
* Defaults to `true` (browser clients sign in once and every page request carries
|
|
127
|
-
* the cookie).
|
|
128
|
-
*
|
|
129
|
-
*
|
|
172
|
+
* the cookie).
|
|
173
|
+
*
|
|
174
|
+
* Pass `false` for a token-only JSON API. Then the cookie is not a credential here:
|
|
175
|
+
* the middleware does not resolve a session from it (and drops one an earlier, laxer
|
|
176
|
+
* mount already resolved from it), and {@link set} does not write it either — so a
|
|
177
|
+
* client that keeps a cookie jar (an HTTP test runner, `curl -b`) never picks up a
|
|
178
|
+
* session it should not have, and stops answering 200 on the step its spec calls
|
|
179
|
+
* "no auth".
|
|
130
180
|
*/
|
|
131
181
|
allowCookieSession?: boolean;
|
|
132
182
|
}
|
|
133
183
|
/**
|
|
134
184
|
* Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
135
|
-
* Falls back to cookie-based session for browser clients unless `allowCookieSession` is `false
|
|
185
|
+
* Falls back to cookie-based session for browser clients unless `allowCookieSession` is `false` — which also stops `set()` writing the session cookie for this request. Auto-refreshes tokens older than `JWT_REFRESH_TIME`.
|
|
136
186
|
* @param options - {@link VerifyMiddlewareOptions} controlling the auto-refresh.
|
|
137
187
|
* @returns An Express-compatible middleware function.
|
|
138
188
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,cAAc,CAAA;AAMrB,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAwB1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MACP,CAAA;AA4B1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,oBAAoB,QAAO;IACtC,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,KAAK,GAAG,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;CAQb,CAAA;AAiDD;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,KAAG,IAE9D,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,8BAA8B,QAAO,IAEjD,CAAA;AAsDD
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,cAAc,CAAA;AAMrB,OAAO,KAAK,EACV,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAwB1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG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*
|
|
246
|
+
* `res.locals` key carrying THIS request's cookie-session policy. {@link verifyMiddleware}
|
|
247
|
+
* writes it from its `allowCookieSession` option; {@link set} reads it. When the value is
|
|
248
|
+
* `false` the request arrived through a mount that authenticates by `Authorization` header
|
|
249
|
+
* only, so `set()` must not hand the client the `token` / `sessionId` / `mol_auth` cookies
|
|
250
|
+
* either: a cookie written here authenticates that same client on its NEXT request (an HTTP
|
|
251
|
+
* test runner's cookie jar, `curl -b`, a browser) through any mount that does accept one,
|
|
252
|
+
* which is how a suite step called "no auth" comes back 200.
|
|
253
|
+
*
|
|
254
|
+
* Exported so a custom auth middleware can declare the same policy for the requests it
|
|
255
|
+
* handles, and so tests can assert the key rather than a string literal.
|
|
256
|
+
*/
|
|
257
|
+
export const ALLOW_COOKIE_SESSION_LOCALS_KEY = 'allowCookieSession';
|
|
258
|
+
/**
|
|
259
|
+
* `res.locals` key carrying HOW this request's session was resolved — `'header'` when
|
|
260
|
+
* the `Authorization` header named the token, `'cookie'` when only the `token` cookie
|
|
261
|
+
* did. {@link verifyMiddleware} writes it alongside `res.locals.session`.
|
|
262
|
+
*
|
|
263
|
+
* A mount with `allowCookieSession: false` reads it to drop a session an EARLIER, laxer
|
|
264
|
+
* mount already resolved out of the cookie (the scaffold mounts `verifyMiddleware` twice,
|
|
265
|
+
* and the first one runs for every `/api` request). A session resolved from the header is
|
|
266
|
+
* never dropped: that client sent its credentials, which is exactly what a token-only API
|
|
267
|
+
* accepts.
|
|
268
|
+
*/
|
|
269
|
+
export const AUTH_SESSION_SOURCE_LOCALS_KEY = 'authSessionSource';
|
|
270
|
+
/**
|
|
271
|
+
* Whether THIS request may be handed a session cookie by {@link set}.
|
|
272
|
+
*
|
|
273
|
+
* {@link verifyMiddleware} records its `allowCookieSession` option in `res.locals`
|
|
274
|
+
* ({@link ALLOW_COOKIE_SESSION_LOCALS_KEY}); an ABSENT record means the request never
|
|
275
|
+
* passed a mount that declares a policy, so the historical default applies (cookies on)
|
|
276
|
+
* and a direct `set()` caller outside the scaffold is unchanged.
|
|
277
|
+
*
|
|
278
|
+
* @param res - The response object.
|
|
279
|
+
* @returns `true` when the session cookies may be written.
|
|
280
|
+
*/
|
|
281
|
+
const maySetSessionCookie = (res) => res.locals?.[ALLOW_COOKIE_SESSION_LOCALS_KEY] !== false;
|
|
282
|
+
/**
|
|
283
|
+
* Set authorization headers and cookie for a session, and RETURN the signed token.
|
|
284
|
+
*
|
|
285
|
+
* To put a session token in a JSON response BODY — an API whose clients send
|
|
286
|
+
* `Authorization: Token <jwt>` — call this and use its return value. Do NOT sign a
|
|
287
|
+
* second token with another key or algorithm: `verifyMiddleware` verifies with the app's
|
|
288
|
+
* bonded `@molecule/api-jwt` provider, so a self-signed one answers 401 on the very next
|
|
289
|
+
* request. Mount `verifyMiddleware({ allowCookieSession: false })` in front of the routes
|
|
290
|
+
* that sign users in and the client gets the token without any session cookie.
|
|
247
291
|
*
|
|
248
292
|
* The token is bound to `session.deviceId`, and `verifyMiddleware` rejects any session whose
|
|
249
293
|
* device row does not exist (that is how signing out revokes a session). Mint the id with
|
|
@@ -251,6 +295,17 @@ const isDeviceActive = async (deviceId) => {
|
|
|
251
295
|
* (register, login, OAuth, password reset), as `handlers/logIn.ts` does: a placeholder
|
|
252
296
|
* (`'unknown'`, `''`, the user's id) yields a token that every later request answers 401.
|
|
253
297
|
*
|
|
298
|
+
* Always sets the `Authorization` response header. Writes the session cookies (the httpOnly
|
|
299
|
+
* `token` and `sessionId`, plus the readable `mol_auth` presence hint) UNLESS the request's
|
|
300
|
+
* cookie-session policy is off — see {@link ALLOW_COOKIE_SESSION_LOCALS_KEY}, written by
|
|
301
|
+
* {@link verifyMiddleware}. A token-only API (`allowCookieSession: false`) gets the header
|
|
302
|
+
* and no cookies, so its clients cannot drift into a cookie session.
|
|
303
|
+
*
|
|
304
|
+
* The policy is the MOUNT's, and the mount records it on every request it passes — including
|
|
305
|
+
* the sign-in request itself, which carries no token and therefore resolves no session. So a
|
|
306
|
+
* token-only API writes no cookie from the very first response: mount
|
|
307
|
+
* `verifyMiddleware({ allowCookieSession: false })` in front of the routes that sign users in.
|
|
308
|
+
*
|
|
254
309
|
* @param _req - The request object (unused; reserved for handler signature parity).
|
|
255
310
|
* @param res - The response object.
|
|
256
311
|
* @param session - The session.
|
|
@@ -268,7 +323,19 @@ export const set = (_req, res, session) => {
|
|
|
268
323
|
const { exp, iat, nbf, ...sessionPayload } = session;
|
|
269
324
|
const token = sign(sessionPayload);
|
|
270
325
|
if (token) {
|
|
326
|
+
// The header is the credential a token-only API's clients read; it is set on
|
|
327
|
+
// every request that mints a token, cookies or not.
|
|
271
328
|
res.setHeader('Authorization', `Bearer ${token}`);
|
|
329
|
+
// A request whose cookie policy is OFF gets the header and NOTHING else. The
|
|
330
|
+
// cookie is not a convenience here — it is a second credential the client did
|
|
331
|
+
// not ask for: once written, an HTTP test runner's cookie jar (Hurl, `curl -b`)
|
|
332
|
+
// or a browser sends it on the NEXT request, including one that sends no
|
|
333
|
+
// `Authorization` header, and a suite step called "no auth" answers 200 where
|
|
334
|
+
// its spec says 401. Gated on the mount's own option (see
|
|
335
|
+
// `allowCookieSession`), so a token-only API cannot hand one out at sign-in.
|
|
336
|
+
if (!maySetSessionCookie(res)) {
|
|
337
|
+
return token;
|
|
338
|
+
}
|
|
272
339
|
// Set as cookies for web browser clients.
|
|
273
340
|
// In production the names are `__Host-`-prefixed (see getAuthCookieName),
|
|
274
341
|
// which REQUIRES Secure + Path=/ + NO Domain — all satisfied by
|
|
@@ -312,12 +379,20 @@ export const set = (_req, res, session) => {
|
|
|
312
379
|
};
|
|
313
380
|
/**
|
|
314
381
|
* Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
315
|
-
* Falls back to cookie-based session for browser clients unless `allowCookieSession` is `false
|
|
382
|
+
* Falls back to cookie-based session for browser clients unless `allowCookieSession` is `false` — which also stops `set()` writing the session cookie for this request. Auto-refreshes tokens older than `JWT_REFRESH_TIME`.
|
|
316
383
|
* @param options - {@link VerifyMiddlewareOptions} controlling the auto-refresh.
|
|
317
384
|
* @returns An Express-compatible middleware function.
|
|
318
385
|
*/
|
|
319
386
|
export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
320
387
|
try {
|
|
388
|
+
// Record THIS mount's cookie policy for the rest of the request, before any
|
|
389
|
+
// early return: `set()` reads it (so a token-only API writes no cookie from the
|
|
390
|
+
// sign-in response on) and a later, stricter mount reads it to know it may
|
|
391
|
+
// strip a session an earlier one resolved out of the cookie. The sign-in
|
|
392
|
+
// request itself carries no token, so the write cannot sit behind the
|
|
393
|
+
// token lookup below.
|
|
394
|
+
const allowCookieSession = options?.allowCookieSession !== false;
|
|
395
|
+
res.locals[ALLOW_COOKIE_SESSION_LOCALS_KEY] = allowCookieSession;
|
|
321
396
|
// Get token from Authorization header, falling back to the `token`
|
|
322
397
|
// cookie that `set()` writes alongside the header. The JSDoc above
|
|
323
398
|
// promises this fallback for browser clients; without it the cookie
|
|
@@ -333,10 +408,20 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
333
408
|
const cookies = req.cookies;
|
|
334
409
|
const cookieToken = readAuthCookie(cookies, 'token');
|
|
335
410
|
const token = headerToken ??
|
|
336
|
-
(
|
|
337
|
-
? cookieToken
|
|
338
|
-
: null);
|
|
411
|
+
(allowCookieSession && typeof cookieToken === 'string' && cookieToken ? cookieToken : null);
|
|
339
412
|
if (!token) {
|
|
413
|
+
// A token-only mount accepts NOTHING from the cookie — not even a session an
|
|
414
|
+
// earlier, laxer mount already resolved out of it. The scaffold mounts
|
|
415
|
+
// `verifyMiddleware` twice (server.ts's `preApiRouter` runs first, then
|
|
416
|
+
// App/router.ts), and the first one runs for every `/api` request: without
|
|
417
|
+
// this the app's own routes would still read `res.locals.session` off the
|
|
418
|
+
// cookie and answer 200 where the spec says 401. A header-resolved session is
|
|
419
|
+
// left alone — that client sent its credentials, which is what a token-only
|
|
420
|
+
// API accepts.
|
|
421
|
+
if (!allowCookieSession && res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY] === 'cookie') {
|
|
422
|
+
delete res.locals.session;
|
|
423
|
+
delete res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY];
|
|
424
|
+
}
|
|
340
425
|
return next();
|
|
341
426
|
}
|
|
342
427
|
// Try to verify the token.
|
|
@@ -361,6 +446,11 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
361
446
|
return next();
|
|
362
447
|
}
|
|
363
448
|
res.locals.session = session;
|
|
449
|
+
// Record HOW the session was resolved, so a later mount with
|
|
450
|
+
// `allowCookieSession: false` can drop a cookie-resolved session (and only
|
|
451
|
+
// that one) — see {@link AUTH_SESSION_SOURCE_LOCALS_KEY}.
|
|
452
|
+
const sessionSource = headerToken ? 'header' : 'cookie';
|
|
453
|
+
res.locals[AUTH_SESSION_SOURCE_LOCALS_KEY] = sessionSource;
|
|
364
454
|
// Auto-refresh the token if it's old enough.
|
|
365
455
|
try {
|
|
366
456
|
const decoded = decode(token);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization.js","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0EAA0E;AAC1E,gFAAgF;AAChF,oCAAoC;AACpC,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAA;AASrE,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B,MAAM,iBAAiB,GAAG,GAAW,EAAE;IACrC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,KAAK,CAAC,C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AAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GAAI,6BAA6B,KAAK,CAAC,QAAQ,MAOlD,KAAK,aAAa,EAAE,KAAK,gBAAgB;;;;;aAPZ,CAAC;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/handlers/create.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAI/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAQzC,mFAAmF;AACnF,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,IAAI,EAAE,KAAK,CAAC,WAAW,GAAG;QACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,UAAU,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACF;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GAAI,6BAA6B,KAAK,CAAC,QAAQ,MAOlD,KAAK,aAAa,EAAE,KAAK,gBAAgB;;;;;aAPZ,CAAC;;;;;;;;;;;;;;;;EAmP7C,CAAA"}
|
package/dist/handlers/create.js
CHANGED
|
@@ -164,9 +164,13 @@ export const create = ({ name, tableName, schema }) => {
|
|
|
164
164
|
catch (error) {
|
|
165
165
|
logger.error(error);
|
|
166
166
|
}
|
|
167
|
-
// Create the id in advance.
|
|
167
|
+
// Create the id in advance — the SAME id keys both rows. `usersSecrets` is
|
|
168
|
+
// read by this id (`usersSecrets.id` = `users.id`) and its DDL declares no
|
|
169
|
+
// foreign key, so a secrets row written under another id inserts fine and is
|
|
170
|
+
// then simply never found: login answers "invalid credentials" forever while
|
|
171
|
+
// a self-read of `users` still succeeds.
|
|
168
172
|
const id = uuid();
|
|
169
|
-
// Create the user
|
|
173
|
+
// Create the user, then the secrets row under that same id.
|
|
170
174
|
const createdResponse = await createResource({ props, id: id });
|
|
171
175
|
if (!createdResponse || createdResponse.statusCode !== 201) {
|
|
172
176
|
return createdResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/handlers/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAE7C,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEjE,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AACrF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEpE,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;AAChC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAU1B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAkB,EAAE,EAAE;IACpE,MAAM,cAAc,GAAG,cAAc,CAAC;QACpC,IAAI;QACJ,SAAS;QACT,MAAM;KACP,CAAC,CAAA;IAEF,OAAO,KAAK,EAAE,GAAkB,EAAE,GAAqB,EAAE,EAAE;QACzD,IAAI,IAAiD,CAAA;QACrD,IAAI,KAAyB,CAAA;QAE7B,IAAI,CAAC;YACH,MAAM,EAAE,QAAQ,EAAE,UAA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I,SAAS;oBAC/B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,SAAS;iBAC9B,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;gBAElB,oEAAoE;gBACpE,iEAAiE;gBACjE,sEAAsE;gBACtE,mEAAmE;gBACnE,MAAM,IAAI,GAAG,yBAAyB,CACpC,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,CAA4B,CAC7E,CAAA;gBACD,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE;iBACzC,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;YACrD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE;oBACJ,KAAK,EAAE,CAAC,CAAC,kCAAkC,CAAC;oBAC5C,QAAQ,EAAE,kCAAkC;iBAC7C;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The `user` resource types, schema, and definition.
|
|
3
3
|
*
|
|
4
|
+
* **This package owns TWO tables, and the key that joins them is the user's own id.**
|
|
5
|
+
* - `users` — {@link Props}: `id`, `username`, `name`, `email`, `emailVerified`, `avatar`,
|
|
6
|
+
* `bio`, `twoFactorEnabled`, the `oauth*` and `plan*` columns. **There is no password column
|
|
7
|
+
* here.**
|
|
8
|
+
* - `usersSecrets` — {@link SecretProps}: `passwordHash`, `passwordResetToken` (and
|
|
9
|
+
* `passwordResetTokenAt`), `twoFactorSecret` / `pendingTwoFactorSecret`, `lastTwoFactorTimeStep`.
|
|
10
|
+
*
|
|
11
|
+
* **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
|
|
12
|
+
* declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces the pairing: a row
|
|
13
|
+
* written under another id is never found again — login answers "invalid credentials" while
|
|
14
|
+
* `GET /api/users/me` (which reads `users` only) still answers 200. A hand-written signup writes
|
|
15
|
+
* both rows from one id:
|
|
16
|
+
* `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
|
|
17
|
+
*
|
|
18
|
+
* Prefer not to hand-write any of that: the handlers this package ships already do it —
|
|
19
|
+
* `handlers.create` (signup: writes both rows, hashes with `@molecule/api-password`, mints the
|
|
20
|
+
* session device), `handlers.logIn` (login: reads `usersSecrets` by the user's id and compares the
|
|
21
|
+
* hash), `handlers.updatePassword`, and `handlers.forgotPassword` / `handlers.resetPassword` (the
|
|
22
|
+
* emailed-token reset). To read or write one secret yourself, use the abstract datastore on the
|
|
23
|
+
* same key — `findById('usersSecrets', userId)`, or `${tableName}Secrets` when the resource
|
|
24
|
+
* carries a custom `tableName` — never SQL.
|
|
25
|
+
*
|
|
4
26
|
* @remarks
|
|
5
27
|
* The user record is split across TWO schemas — pick the right one or you leak credentials:
|
|
6
28
|
* - **{@link Props} (`propsSchema`)** — SAFE, client-facing fields (username, name, email,
|
|
7
29
|
* `emailVerified`, `twoFactorEnabled`, plan). This is what handlers return and what lives
|
|
8
30
|
* in the `users` table.
|
|
9
31
|
* - **{@link SecretProps} (`secretPropsSchema`)** — SERVER-ONLY secrets: `passwordHash`, the
|
|
10
|
-
* TOTP `twoFactorSecret` (and its pending-setup value). Stored in
|
|
11
|
-
* and NEVER serialized to the client. Note the pair
|
|
12
|
-
* `Props`) vs `twoFactorSecret` (secret, in `SecretProps`).
|
|
32
|
+
* TOTP `twoFactorSecret` (and its pending-setup value). Stored in the SEPARATE `usersSecrets`
|
|
33
|
+
* table (keyed by `id` = the user's id) and NEVER serialized to the client. Note the pair
|
|
34
|
+
* `twoFactorEnabled` (safe boolean, in `Props`) vs `twoFactorSecret` (secret, in `SecretProps`).
|
|
13
35
|
*
|
|
14
36
|
* When you extend the user, put a secret (token, hash, key, provider refresh token) in
|
|
15
37
|
* `SecretProps`; put a display field in `Props`. **Never add a secret to `Props`, never
|
|
@@ -35,11 +57,20 @@
|
|
|
35
57
|
* sent (letters, digits, `.`, `-`, `_`); anything else is answered 400
|
|
36
58
|
* `user.error.usernameInvalid`, never rewritten.
|
|
37
59
|
*
|
|
38
|
-
* **A token-only JSON API:**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* whose clients send the
|
|
60
|
+
* **A token-only JSON API:** by default the `token` cookie that login sets IS a session,
|
|
61
|
+
* and `authorization.set()` writes it on every sign-in — so a client that keeps a cookie
|
|
62
|
+
* jar (an HTTP test runner, `curl -b`) stays signed in on a request that sends no
|
|
63
|
+
* `Authorization` header, and gets 200 on the step the suite calls "no auth". Mount
|
|
64
|
+
* `verifyMiddleware({ allowCookieSession: false })` for an API whose clients send the
|
|
65
|
+
* header: that ONE option turns the cookie off in BOTH directions — the middleware no
|
|
66
|
+
* longer resolves a session from it (nor keeps one an earlier, laxer mount resolved), and
|
|
67
|
+
* `set()` stops writing `token` / `sessionId` / `mol_auth`, so even the sign-in response
|
|
68
|
+
* carries the `Authorization` header alone and the jar never fills. Set it on the mount in
|
|
69
|
+
* front of the routes that sign users in — the scaffold's `api/src/App/router.ts` — and
|
|
70
|
+
* check for a SECOND one: a request can pass several mounts (`api/src/server.ts`'s
|
|
71
|
+
* `preApiRouter` runs before `App/router.ts` and covers all of `/api`), the last one it
|
|
72
|
+
* passes sets the policy both halves read, and a laxer mount later in the chain cannot
|
|
73
|
+
* re-admit the cookie. If the app mounts two, mount it once instead.
|
|
43
74
|
*
|
|
44
75
|
* **Revoking a session yourself:** the middleware caches "this device exists" for 10 s per
|
|
45
76
|
* process, so a hand-written logout that deletes the `devices` row keeps authorizing that
|
|
@@ -79,7 +110,7 @@
|
|
|
79
110
|
* ```ts
|
|
80
111
|
* // Extend safely: a display field in Props, a secret in SecretProps.
|
|
81
112
|
* // propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
82
|
-
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only,
|
|
113
|
+
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
|
83
114
|
*
|
|
84
115
|
* // A custom handler returns SAFE props — never the secrets row.
|
|
85
116
|
* router.get('/me/timezone', async (req, res) => {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AAEH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The `user` resource types, schema, and definition.
|
|
3
3
|
*
|
|
4
|
+
* **This package owns TWO tables, and the key that joins them is the user's own id.**
|
|
5
|
+
* - `users` — {@link Props}: `id`, `username`, `name`, `email`, `emailVerified`, `avatar`,
|
|
6
|
+
* `bio`, `twoFactorEnabled`, the `oauth*` and `plan*` columns. **There is no password column
|
|
7
|
+
* here.**
|
|
8
|
+
* - `usersSecrets` — {@link SecretProps}: `passwordHash`, `passwordResetToken` (and
|
|
9
|
+
* `passwordResetTokenAt`), `twoFactorSecret` / `pendingTwoFactorSecret`, `lastTwoFactorTimeStep`.
|
|
10
|
+
*
|
|
11
|
+
* **`usersSecrets.id` IS the user's id — the value of `users.id`, never a fresh uuid.** The DDL
|
|
12
|
+
* declares it `UNIQUE PRIMARY KEY` with no foreign key, so nothing enforces the pairing: a row
|
|
13
|
+
* written under another id is never found again — login answers "invalid credentials" while
|
|
14
|
+
* `GET /api/users/me` (which reads `users` only) still answers 200. A hand-written signup writes
|
|
15
|
+
* both rows from one id:
|
|
16
|
+
* `const id = uuid(); await create('users', { ...props, id }); await create('usersSecrets', { id, passwordHash: await hash(password) })`.
|
|
17
|
+
*
|
|
18
|
+
* Prefer not to hand-write any of that: the handlers this package ships already do it —
|
|
19
|
+
* `handlers.create` (signup: writes both rows, hashes with `@molecule/api-password`, mints the
|
|
20
|
+
* session device), `handlers.logIn` (login: reads `usersSecrets` by the user's id and compares the
|
|
21
|
+
* hash), `handlers.updatePassword`, and `handlers.forgotPassword` / `handlers.resetPassword` (the
|
|
22
|
+
* emailed-token reset). To read or write one secret yourself, use the abstract datastore on the
|
|
23
|
+
* same key — `findById('usersSecrets', userId)`, or `${tableName}Secrets` when the resource
|
|
24
|
+
* carries a custom `tableName` — never SQL.
|
|
25
|
+
*
|
|
4
26
|
* @remarks
|
|
5
27
|
* The user record is split across TWO schemas — pick the right one or you leak credentials:
|
|
6
28
|
* - **{@link Props} (`propsSchema`)** — SAFE, client-facing fields (username, name, email,
|
|
7
29
|
* `emailVerified`, `twoFactorEnabled`, plan). This is what handlers return and what lives
|
|
8
30
|
* in the `users` table.
|
|
9
31
|
* - **{@link SecretProps} (`secretPropsSchema`)** — SERVER-ONLY secrets: `passwordHash`, the
|
|
10
|
-
* TOTP `twoFactorSecret` (and its pending-setup value). Stored in
|
|
11
|
-
* and NEVER serialized to the client. Note the pair
|
|
12
|
-
* `Props`) vs `twoFactorSecret` (secret, in `SecretProps`).
|
|
32
|
+
* TOTP `twoFactorSecret` (and its pending-setup value). Stored in the SEPARATE `usersSecrets`
|
|
33
|
+
* table (keyed by `id` = the user's id) and NEVER serialized to the client. Note the pair
|
|
34
|
+
* `twoFactorEnabled` (safe boolean, in `Props`) vs `twoFactorSecret` (secret, in `SecretProps`).
|
|
13
35
|
*
|
|
14
36
|
* When you extend the user, put a secret (token, hash, key, provider refresh token) in
|
|
15
37
|
* `SecretProps`; put a display field in `Props`. **Never add a secret to `Props`, never
|
|
@@ -35,11 +57,20 @@
|
|
|
35
57
|
* sent (letters, digits, `.`, `-`, `_`); anything else is answered 400
|
|
36
58
|
* `user.error.usernameInvalid`, never rewritten.
|
|
37
59
|
*
|
|
38
|
-
* **A token-only JSON API:**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* whose clients send the
|
|
60
|
+
* **A token-only JSON API:** by default the `token` cookie that login sets IS a session,
|
|
61
|
+
* and `authorization.set()` writes it on every sign-in — so a client that keeps a cookie
|
|
62
|
+
* jar (an HTTP test runner, `curl -b`) stays signed in on a request that sends no
|
|
63
|
+
* `Authorization` header, and gets 200 on the step the suite calls "no auth". Mount
|
|
64
|
+
* `verifyMiddleware({ allowCookieSession: false })` for an API whose clients send the
|
|
65
|
+
* header: that ONE option turns the cookie off in BOTH directions — the middleware no
|
|
66
|
+
* longer resolves a session from it (nor keeps one an earlier, laxer mount resolved), and
|
|
67
|
+
* `set()` stops writing `token` / `sessionId` / `mol_auth`, so even the sign-in response
|
|
68
|
+
* carries the `Authorization` header alone and the jar never fills. Set it on the mount in
|
|
69
|
+
* front of the routes that sign users in — the scaffold's `api/src/App/router.ts` — and
|
|
70
|
+
* check for a SECOND one: a request can pass several mounts (`api/src/server.ts`'s
|
|
71
|
+
* `preApiRouter` runs before `App/router.ts` and covers all of `/api`), the last one it
|
|
72
|
+
* passes sets the policy both halves read, and a laxer mount later in the chain cannot
|
|
73
|
+
* re-admit the cookie. If the app mounts two, mount it once instead.
|
|
43
74
|
*
|
|
44
75
|
* **Revoking a session yourself:** the middleware caches "this device exists" for 10 s per
|
|
45
76
|
* process, so a hand-written logout that deletes the `devices` row keeps authorizing that
|
|
@@ -79,7 +110,7 @@
|
|
|
79
110
|
* ```ts
|
|
80
111
|
* // Extend safely: a display field in Props, a secret in SecretProps.
|
|
81
112
|
* // propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
82
|
-
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only,
|
|
113
|
+
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
|
83
114
|
*
|
|
84
115
|
* // A custom handler returns SAFE props — never the secrets row.
|
|
85
116
|
* router.get('/me/timezone', async (req, res) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+IG;AAEH,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,WAAW,MAAM,wBAAwB,CAAA;AACrD,cAAc,oBAAoB,CAAA;AAClC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,wBAAwB,CAAA;AACtC,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAA"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -68,11 +68,13 @@ export declare const propsSchema: z.ZodObject<{
|
|
|
68
68
|
planAutoRenews: z.ZodOptional<z.ZodBoolean>;
|
|
69
69
|
}, z.core.$strip>;
|
|
70
70
|
/**
|
|
71
|
-
* User props type inferred from schema
|
|
71
|
+
* User props type inferred from schema — the row shape of the `users` table, which holds no
|
|
72
|
+
* password.
|
|
72
73
|
*/
|
|
73
74
|
export type Props = z.infer<typeof propsSchema>;
|
|
74
75
|
/**
|
|
75
|
-
* Secret properties stored in
|
|
76
|
+
* Secret properties stored in the separate `usersSecrets` table, keyed by `id` = the user's id
|
|
77
|
+
* (the value of `users.id`, never a fresh uuid).
|
|
76
78
|
*/
|
|
77
79
|
export declare const secretPropsSchema: z.ZodObject<{
|
|
78
80
|
id: z.ZodString;
|
|
@@ -84,7 +86,7 @@ export declare const secretPropsSchema: z.ZodObject<{
|
|
|
84
86
|
lastTwoFactorTimeStep: z.ZodOptional<z.ZodNumber>;
|
|
85
87
|
}, z.core.$strip>;
|
|
86
88
|
/**
|
|
87
|
-
* Secret
|
|
89
|
+
* Secret props type — the row shape of the `usersSecrets` table, whose `id` is the user's id.
|
|
88
90
|
*/
|
|
89
91
|
export type SecretProps = z.infer<typeof secretPropsSchema>;
|
|
90
92
|
/**
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;A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;;iBAI3B,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AAE7E;;GAEG;AACH,eAAO,MAAM,gCAAgC;;;iBAKjC,CAAA;AAEZ;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAA;AAEzF,qFAAqF;AACrF,eAAO,MAAM,aAAa;;;;;;iBAqBxB,CAAA;AAEF;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAEnD;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,CAAA"}
|
package/dist/schema.js
CHANGED
|
@@ -99,7 +99,8 @@ export const createSchema = (options) => {
|
|
|
99
99
|
*/
|
|
100
100
|
export const propsSchema = createSchema();
|
|
101
101
|
/**
|
|
102
|
-
* Secret properties stored in
|
|
102
|
+
* Secret properties stored in the separate `usersSecrets` table, keyed by `id` = the user's id
|
|
103
|
+
* (the value of `users.id`, never a fresh uuid).
|
|
103
104
|
*/
|
|
104
105
|
export const secretPropsSchema = z.object({
|
|
105
106
|
/**
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAA;AAElC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,CAAA;AAE3C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAG1B,OAID,EAAE,EAAE;IACH,OAAO,e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