@molecule/api-resource-user 1.8.2 → 1.8.3
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 +33 -6
- 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-11-
|
|
6
|
+
Generated: 2026-11-04T14:20:01.202Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -961,8 +961,13 @@ sameSite: 'none', partitioned: true, path: '/' }`. The molecule.dev live
|
|
|
961
961
|
{@link getAuthCookieName}). NEVER weaken it.
|
|
962
962
|
- **Development, top-level** → `{ secure: false, sameSite: 'lax', path: '/' }`.
|
|
963
963
|
The original dev posture (plain http, not `Secure`) — used by the molecule.dev
|
|
964
|
+
IDE and by a developer running their generated app locally. Both are top-level
|
|
965
|
+
documents, so `Lax` is correct and `Secure`/`None`/`Partitioned` would be both
|
|
966
|
+
unnecessary and (as above) actively harmful.
|
|
964
967
|
|
|
965
|
-
|
|
968
|
+
`httpOnly` and `maxAge` are intentionally omitted: the SET call adds those per
|
|
969
|
+
cookie, and the CLEAR call spreads these attributes verbatim so the deletion
|
|
970
|
+
targets the exact same (possibly Partitioned) cookie jar.
|
|
966
971
|
|
|
967
972
|
```typescript
|
|
968
973
|
function getAuthCookieOptions(): {
|
|
@@ -1126,8 +1131,30 @@ to mint a token without one: it throws when `session.userId` or `session.deviceI
|
|
|
1126
1131
|
is not a non-empty string, naming the field and the call that supplies it, instead of letting the
|
|
1127
1132
|
client discover it as a 401 on every later request. Do the device step on every path that signs a
|
|
1128
1133
|
user in (register, login, OAuth, password reset), as `handlers/logIn.ts` does: a placeholder
|
|
1129
|
-
|
|
1130
|
-
|
|
1134
|
+
(`'unknown'`, `''`, the user's id) yields a token that every later request answers 401.
|
|
1135
|
+
|
|
1136
|
+
To put a session token in a JSON response BODY — an API whose clients send
|
|
1137
|
+
`Authorization: Token <jwt>` — call this and use its return value; the shipped `logIn` and
|
|
1138
|
+
`create` handlers already return it as `accessToken`. Do NOT sign a
|
|
1139
|
+
second token with another key or algorithm: `verifyMiddleware` verifies with the app's
|
|
1140
|
+
bonded `@molecule/api-jwt` provider, so a self-signed one answers 401 on the very next
|
|
1141
|
+
request. Mount `verifyMiddleware({ allowCookieSession: false, scheme: 'Token' })` in front
|
|
1142
|
+
of the routes that sign users in and the client gets the token in that scheme with no
|
|
1143
|
+
session cookie. (`AUTH_SCHEME=Token` in the app's environment does the same for every
|
|
1144
|
+
mount — the scheme is configuration, not a second auth path.)
|
|
1145
|
+
|
|
1146
|
+
Always sets the `Authorization` response header — labelled with the request mount's scheme
|
|
1147
|
+
(`Bearer` by default, `Token` for a RealWorld-style API; see {@link AUTH_SCHEME_LOCALS_KEY}
|
|
1148
|
+
and `AUTH_SCHEME`). Writes the session cookies (the httpOnly
|
|
1149
|
+
`token` and `sessionId`, plus the readable `mol_auth` presence hint) UNLESS the request's
|
|
1150
|
+
cookie-session policy is off — see {@link ALLOW_COOKIE_SESSION_LOCALS_KEY}, written by
|
|
1151
|
+
{@link verifyMiddleware}. A token-only API (`allowCookieSession: false`) gets the header
|
|
1152
|
+
and no cookies, so its clients cannot drift into a cookie session.
|
|
1153
|
+
|
|
1154
|
+
The policy is the MOUNT's, and the mount records it on every request it passes — including
|
|
1155
|
+
the sign-in request itself, which carries no token and therefore resolves no session. So a
|
|
1156
|
+
token-only API writes no cookie from the very first response: mount
|
|
1157
|
+
`verifyMiddleware({ allowCookieSession: false })` in front of the routes that sign users in.
|
|
1131
1158
|
|
|
1132
1159
|
```typescript
|
|
1133
1160
|
function set(_req: MoleculeRequest, res: MoleculeResponse, session: Session): string | null
|
|
@@ -2010,8 +2037,8 @@ arrived on stays, and the token that made the request (the `Authorization` heade
|
|
|
2010
2037
|
is holding) keeps working. A RealWorld-style suite changes the password and then keeps using
|
|
2011
2038
|
the same token for the next request; revoking the caller too is what answered its second
|
|
2012
2039
|
`PUT /user` with 401. Do not fold a per-user secret into the
|
|
2013
|
-
|
|
2014
|
-
|
|
2040
|
+
JWT: the device row is the revocation lever. A caller with no session (a handler invoked
|
|
2041
|
+
outside a request) falls back to revoking every device.
|
|
2015
2042
|
|
|
2016
2043
|
```typescript
|
|
2017
2044
|
function updatePassword({
|