@molecule/api-jwt 1.0.4 → 1.0.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/README.md +15 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +6 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +6 -0
- package/dist/provider.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-16T09:59:40.216Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-jwt
|
|
@@ -237,6 +237,12 @@ function hasProvider(): boolean
|
|
|
237
237
|
Signs a payload into a JWT string using the bonded provider. Uses the
|
|
238
238
|
configured algorithm, expiry, and private key as defaults.
|
|
239
239
|
|
|
240
|
+
This is the LOW-LEVEL signer: it signs whatever payload it is given, and a
|
|
241
|
+
token it mints is not by itself a session. For a session, use
|
|
242
|
+
`authorization.set()` from `@molecule/api-resource-user` — the app's global
|
|
243
|
+
`verifyMiddleware` accepts a JWT only when its payload also carries a
|
|
244
|
+
`deviceId` naming an active row in `devices` (see the module `@remarks`).
|
|
245
|
+
|
|
240
246
|
```typescript
|
|
241
247
|
function sign(
|
|
242
248
|
object: JSONObject,
|
|
@@ -379,6 +385,14 @@ anything security-relevant; `decode()` is only for reading a token you do NOT tr
|
|
|
379
385
|
and populates `res.locals.session`, so a handler calls `getUserId(res)` — do NOT call
|
|
380
386
|
`verify()`/`sign()` by hand for the session (see the `auth` skill). Use these directly
|
|
381
387
|
only for a CUSTOM token, e.g. a signed email/reset link.
|
|
388
|
+
- **{@link sign} is the low-level signer; a token it mints is NOT a session.**
|
|
389
|
+
`verifyMiddleware` (`@molecule/api-resource-user`) accepts a JWT only when its payload
|
|
390
|
+
also carries a `deviceId` naming an ACTIVE row in the app's `devices` table, so a
|
|
391
|
+
payload without one is treated as no session: `sign({ userId })` answers 401 on every
|
|
392
|
+
route although the token itself verifies. Mint a session with `authorization.set()`
|
|
393
|
+
from `@molecule/api-resource-user`, which signs and writes the session cookies — call
|
|
394
|
+
`get('device').createOrUpdate(userId, deviceName)` first and pass `{ userId, deviceId }`
|
|
395
|
+
to `set()`, as that package's own log-in handler does.
|
|
382
396
|
- **Re-signing decoded claims (refresh flows): strip `exp`/`iat` first.** `sign()`
|
|
383
397
|
always sets `expiresIn` (default {@link JWT_EXPIRES_TIME}), and the underlying library
|
|
384
398
|
throws (`Bad "options.expiresIn" option the payload already has an "exp" property`)
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
* and populates `res.locals.session`, so a handler calls `getUserId(res)` — do NOT call
|
|
22
22
|
* `verify()`/`sign()` by hand for the session (see the `auth` skill). Use these directly
|
|
23
23
|
* only for a CUSTOM token, e.g. a signed email/reset link.
|
|
24
|
+
* - **{@link sign} is the low-level signer; a token it mints is NOT a session.**
|
|
25
|
+
* `verifyMiddleware` (`@molecule/api-resource-user`) accepts a JWT only when its payload
|
|
26
|
+
* also carries a `deviceId` naming an ACTIVE row in the app's `devices` table, so a
|
|
27
|
+
* payload without one is treated as no session: `sign({ userId })` answers 401 on every
|
|
28
|
+
* route although the token itself verifies. Mint a session with `authorization.set()`
|
|
29
|
+
* from `@molecule/api-resource-user`, which signs and writes the session cookies — call
|
|
30
|
+
* `get('device').createOrUpdate(userId, deviceName)` first and pass `{ userId, deviceId }`
|
|
31
|
+
* to `set()`, as that package's own log-in handler does.
|
|
24
32
|
* - **Re-signing decoded claims (refresh flows): strip `exp`/`iat` first.** `sign()`
|
|
25
33
|
* always sets `expiresIn` (default {@link JWT_EXPIRES_TIME}), and the underlying library
|
|
26
34
|
* throws (`Bad "options.expiresIn" option the payload already has an "exp" property`)
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,14 @@
|
|
|
21
21
|
* and populates `res.locals.session`, so a handler calls `getUserId(res)` — do NOT call
|
|
22
22
|
* `verify()`/`sign()` by hand for the session (see the `auth` skill). Use these directly
|
|
23
23
|
* only for a CUSTOM token, e.g. a signed email/reset link.
|
|
24
|
+
* - **{@link sign} is the low-level signer; a token it mints is NOT a session.**
|
|
25
|
+
* `verifyMiddleware` (`@molecule/api-resource-user`) accepts a JWT only when its payload
|
|
26
|
+
* also carries a `deviceId` naming an ACTIVE row in the app's `devices` table, so a
|
|
27
|
+
* payload without one is treated as no session: `sign({ userId })` answers 401 on every
|
|
28
|
+
* route although the token itself verifies. Mint a session with `authorization.set()`
|
|
29
|
+
* from `@molecule/api-resource-user`, which signs and writes the session cookies — call
|
|
30
|
+
* `get('device').createOrUpdate(userId, deviceName)` first and pass `{ userId, deviceId }`
|
|
31
|
+
* to `set()`, as that package's own log-in handler does.
|
|
24
32
|
* - **Re-signing decoded claims (refresh flows): strip `exp`/`iat` first.** `sign()`
|
|
25
33
|
* always sets `expiresIn` (default {@link JWT_EXPIRES_TIME}), and the underlying library
|
|
26
34
|
* throws (`Bad "options.expiresIn" option the payload already has an "exp" property`)
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -50,6 +50,12 @@ export declare const hasProvider: () => boolean;
|
|
|
50
50
|
* Signs a payload into a JWT string using the bonded provider. Uses the
|
|
51
51
|
* configured algorithm, expiry, and private key as defaults.
|
|
52
52
|
*
|
|
53
|
+
* This is the LOW-LEVEL signer: it signs whatever payload it is given, and a
|
|
54
|
+
* token it mints is not by itself a session. For a session, use
|
|
55
|
+
* `authorization.set()` from `@molecule/api-resource-user` — the app's global
|
|
56
|
+
* `verifyMiddleware` accepts a JWT only when its payload also carries a
|
|
57
|
+
* `deviceId` naming an active row in `devices` (see the module `@remarks`).
|
|
58
|
+
*
|
|
53
59
|
* @param object - The JSON payload to sign.
|
|
54
60
|
* @param options - Signing options; `algorithm` defaults to `JWT_ALGORITHM`, `expiresIn` defaults to `JWT_EXPIRES_TIME`.
|
|
55
61
|
* @param options.algorithm - The signing algorithm (e.g. `RS256`, `HS256`).
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,WAAW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M,GAAG,MAAuB,KAC1C,MAAM,GAAG,UAA6E,CAAA;AAEzF;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,EAAE,UAAU,gBAAgB,KAAG,MAAM,GAAG,UAAU,GAAG,IACnD,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -99,6 +99,12 @@ export const hasProvider = () => {
|
|
|
99
99
|
* Signs a payload into a JWT string using the bonded provider. Uses the
|
|
100
100
|
* configured algorithm, expiry, and private key as defaults.
|
|
101
101
|
*
|
|
102
|
+
* This is the LOW-LEVEL signer: it signs whatever payload it is given, and a
|
|
103
|
+
* token it mints is not by itself a session. For a session, use
|
|
104
|
+
* `authorization.set()` from `@molecule/api-resource-user` — the app's global
|
|
105
|
+
* `verifyMiddleware` accepts a JWT only when its payload also carries a
|
|
106
|
+
* `deviceId` naming an active row in `devices` (see the module `@remarks`).
|
|
107
|
+
*
|
|
102
108
|
* @param object - The JSON payload to sign.
|
|
103
109
|
* @param options - Signing options; `algorithm` defaults to `JWT_ALGORITHM`, `expiresIn` defaults to `JWT_EXPIRES_TIME`.
|
|
104
110
|
* @param options.algorithm - The signing algorithm (e.g. `RS256`, `HS256`).
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAElG,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAW3D,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAE1B,MAAM,SAAS,GAAG,KAAK,CAAA;AACvB,UAAU,CAAC,SAAS,CAAC,CAAA;AAErB,8DAA8D;AAC9D,MAAM,oBAAoB,GAA4B;IACpD,OAAO;IACP,OAAO;IAC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