@molecule/api-resource-user 1.10.4 → 1.11.2
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 +48 -21
- package/dist/authorization.d.ts +14 -1
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +67 -3
- package/dist/authorization.js.map +1 -1
- package/dist/handlers/forgotPassword.d.ts +6 -4
- package/dist/handlers/forgotPassword.d.ts.map +1 -1
- package/dist/handlers/forgotPassword.js +58 -53
- package/dist/handlers/forgotPassword.js.map +1 -1
- package/dist/handlers/readSelf.d.ts +3 -1
- package/dist/handlers/readSelf.d.ts.map +1 -1
- package/dist/handlers/readSelf.js +5 -2
- package/dist/handlers/readSelf.js.map +1 -1
- package/dist/index.d.ts +16 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/routes.d.ts +6 -0
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +7 -0
- package/dist/routes.js.map +1 -1
- package/dist/scaffold-router.d.ts +5 -1
- package/dist/scaffold-router.d.ts.map +1 -1
- package/dist/scaffold-router.js +9 -5
- package/dist/scaffold-router.js.map +1 -1
- package/package.json +2 -2
- package/src/scaffold-router.ts +28 -18
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-24T08:40:50.887Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/api-resource-user
|
|
@@ -208,6 +208,10 @@ changes through the auth pages (`useAuth()`). There is no supported bypass to ad
|
|
|
208
208
|
## Quick Start
|
|
209
209
|
|
|
210
210
|
```ts
|
|
211
|
+
// The routes it mounts (under /api) answer:
|
|
212
|
+
// POST /users, POST /users/log-in → { props, accessToken, user }; bad credentials → 403, not 401
|
|
213
|
+
// GET /users/me → { props, user }; signed out → 401
|
|
214
|
+
|
|
211
215
|
// Extend safely: a display field in Props, a secret in SecretProps.
|
|
212
216
|
// propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
213
217
|
// secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
|
@@ -228,7 +232,7 @@ router.get('/me/timezone', async (req, res) => {
|
|
|
228
232
|
## Installation
|
|
229
233
|
|
|
230
234
|
```bash
|
|
231
|
-
npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config @molecule/api-database @molecule/api-
|
|
235
|
+
npm install @molecule/api-resource-user @molecule/api-bond @molecule/api-config @molecule/api-database @molecule/api-i18n @molecule/api-jwt @molecule/api-locales-user @molecule/api-locales-user-payments @molecule/api-password @molecule/api-rate-limit @molecule/api-resource @molecule/api-resource-device @molecule/api-secrets express uuid zod
|
|
232
236
|
npm install -D @types/express
|
|
233
237
|
```
|
|
234
238
|
|
|
@@ -974,6 +978,7 @@ const routes: (
|
|
|
974
978
|
| { method: 'get'; path: string; middlewares: string[]; handler: string; optional?: undefined }
|
|
975
979
|
| { method: 'patch'; path: string; middlewares: string[]; handler: string; optional?: undefined }
|
|
976
980
|
| { method: 'delete'; path: string; middlewares: string[]; handler: string; optional?: undefined }
|
|
981
|
+
| { method: 'patch'; path: string; middlewares: string[]; handler: string; optional: string }
|
|
977
982
|
)[]
|
|
978
983
|
```
|
|
979
984
|
|
|
@@ -1513,6 +1518,12 @@ interface VerifyMiddlewareOptions {
|
|
|
1513
1518
|
* with (`createFetchClient({ baseURL, authScheme: 'Token' })`).
|
|
1514
1519
|
*/
|
|
1515
1520
|
scheme?: string
|
|
1521
|
+
/**
|
|
1522
|
+
* Origins (`https://app.example.com`) that may send cookie-authenticated writes from another
|
|
1523
|
+
* site, added to the `APP_ORIGIN` / `SITE_ORIGIN` values (comma-separated) the app already
|
|
1524
|
+
* sets for CORS. See {@link verifyMiddleware} for the cross-site write rule they relax.
|
|
1525
|
+
*/
|
|
1526
|
+
trustedOrigins?: readonly string[]
|
|
1516
1527
|
}
|
|
1517
1528
|
```
|
|
1518
1529
|
|
|
@@ -1534,11 +1545,18 @@ optional viewer with `getUserId(res)` (from `@molecule/api-bonds-default-express
|
|
|
1534
1545
|
when signed out), and a route that requires sign-in answers 401 itself when that is `null`,
|
|
1535
1546
|
in the app's own error shape. `authorizers.auth()` is the same check as route middleware.
|
|
1536
1547
|
|
|
1548
|
+
**The cookie does not authenticate another site's writes.** A POST, PUT, PATCH or DELETE that
|
|
1549
|
+
carries only the session cookie, and that the browser labels `Sec-Fetch-Site: same-site` or
|
|
1550
|
+
`cross-site`, continues without a session (the request reaches the route signed out) unless
|
|
1551
|
+
its `Origin` is listed in `APP_ORIGIN`, `SITE_ORIGIN` or `trustedOrigins`. The app's own pages
|
|
1552
|
+
(`same-origin`), `Authorization` headers, safe methods and clients that send no
|
|
1553
|
+
`Sec-Fetch-Site` are unaffected.
|
|
1554
|
+
|
|
1537
1555
|
```typescript
|
|
1538
1556
|
function verifyMiddleware(options?: VerifyMiddlewareOptions): MoleculeRequestHandler
|
|
1539
1557
|
```
|
|
1540
1558
|
|
|
1541
|
-
- `options` — {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy and
|
|
1559
|
+
- `options` — {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy, scheme and trusted origins.
|
|
1542
1560
|
|
|
1543
1561
|
**Returns:** An Express-compatible middleware function.
|
|
1544
1562
|
|
|
@@ -1820,9 +1838,10 @@ interface ForgotPasswordRequest extends MoleculeRequest {
|
|
|
1820
1838
|
|
|
1821
1839
|
##### `handlers.forgotPassword(resource)`
|
|
1822
1840
|
|
|
1823
|
-
Generates a
|
|
1824
|
-
email via the bonded email provider
|
|
1825
|
-
|
|
1841
|
+
Generates a password reset token, stores its hash in the secrets table, and sends a reset
|
|
1842
|
+
email via the bonded email provider. Returns 200 whether or not the email exists, to prevent
|
|
1843
|
+
user enumeration. With no email provider bonded it returns 501
|
|
1844
|
+
`user.error.passwordResetUnavailable` for every address, since no reset email can be sent.
|
|
1826
1845
|
|
|
1827
1846
|
```typescript
|
|
1828
1847
|
function forgotPassword({
|
|
@@ -1842,7 +1861,7 @@ function forgotPassword({
|
|
|
1842
1861
|
- `resource.tableName` — The database table name for users.
|
|
1843
1862
|
- `resource.schema` — Optional. Ignored — the reset flow reads and writes secrets directly.
|
|
1844
1863
|
|
|
1845
|
-
**Returns:** A request handler that responds with `{ statusCode: 200, body: { success: true } }
|
|
1864
|
+
**Returns:** A request handler that responds with `{ statusCode: 200, body: { success: true } }`, or 501 when no email provider is bonded.
|
|
1846
1865
|
|
|
1847
1866
|
##### `handlers.LogInRequest`
|
|
1848
1867
|
|
|
@@ -2208,9 +2227,9 @@ function readSelf({
|
|
|
2208
2227
|
```
|
|
2209
2228
|
|
|
2210
2229
|
- `resource` — The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
2211
|
-
- `resource.tableName` — The database table name for users.
|
|
2230
|
+
- `resource.tableName` — The database table name for users. The user comes back as both `props` and `user` (the same object), the shape sign-up and log-in answer with, so one reader serves all three.
|
|
2212
2231
|
|
|
2213
|
-
**Returns:** A request handler responding `{ statusCode: 200, body: { props, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
2232
|
+
**Returns:** A request handler responding `{ statusCode: 200, body: { props, user, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
2214
2233
|
|
|
2215
2234
|
##### `handlers.RESET_TOKEN_TTL_MS`
|
|
2216
2235
|
|
|
@@ -2819,19 +2838,19 @@ Peer dependencies:
|
|
|
2819
2838
|
- `@molecule/api-bond` ^1.0.1
|
|
2820
2839
|
- `@molecule/api-config` ^1.0.1
|
|
2821
2840
|
- `@molecule/api-database` ^1.2.2
|
|
2822
|
-
- `@molecule/api-entitlements` ^1.0.1
|
|
2841
|
+
- `@molecule/api-entitlements` ^1.0.1 _(optional)_
|
|
2823
2842
|
- `@molecule/api-i18n` ^1.0.1
|
|
2824
2843
|
- `@molecule/api-jwt` ^1.0.1
|
|
2825
2844
|
- `@molecule/api-locales-user` ^1.0.1
|
|
2826
2845
|
- `@molecule/api-locales-user-payments` ^1.0.1
|
|
2827
2846
|
- `@molecule/api-password` ^1.0.1
|
|
2828
|
-
- `@molecule/api-payments` ^1.1.0
|
|
2829
|
-
- `@molecule/api-push-notifications` ^1.0.1
|
|
2847
|
+
- `@molecule/api-payments` ^1.1.0 _(optional)_
|
|
2848
|
+
- `@molecule/api-push-notifications` ^1.0.1 _(optional)_
|
|
2830
2849
|
- `@molecule/api-rate-limit` ^1.0.1
|
|
2831
2850
|
- `@molecule/api-resource` ^1.0.1
|
|
2832
2851
|
- `@molecule/api-resource-device` ^1.1.4
|
|
2833
2852
|
- `@molecule/api-secrets` ^1.0.1
|
|
2834
|
-
- `@molecule/api-two-factor` ^1.0.1
|
|
2853
|
+
- `@molecule/api-two-factor` ^1.0.1 _(optional)_
|
|
2835
2854
|
- `express` ^5.0.0
|
|
2836
2855
|
|
|
2837
2856
|
### Environment Variables
|
|
@@ -2846,19 +2865,19 @@ Peer dependencies:
|
|
|
2846
2865
|
- `@molecule/api-bond`
|
|
2847
2866
|
- `@molecule/api-config`
|
|
2848
2867
|
- `@molecule/api-database`
|
|
2849
|
-
- `@molecule/api-entitlements`
|
|
2868
|
+
- `@molecule/api-entitlements` _(optional)_
|
|
2850
2869
|
- `@molecule/api-i18n`
|
|
2851
2870
|
- `@molecule/api-jwt`
|
|
2852
2871
|
- `@molecule/api-locales-user`
|
|
2853
2872
|
- `@molecule/api-locales-user-payments`
|
|
2854
2873
|
- `@molecule/api-password`
|
|
2855
|
-
- `@molecule/api-payments`
|
|
2856
|
-
- `@molecule/api-push-notifications`
|
|
2874
|
+
- `@molecule/api-payments` _(optional)_
|
|
2875
|
+
- `@molecule/api-push-notifications` _(optional)_
|
|
2857
2876
|
- `@molecule/api-rate-limit`
|
|
2858
2877
|
- `@molecule/api-resource`
|
|
2859
2878
|
- `@molecule/api-resource-device`
|
|
2860
2879
|
- `@molecule/api-secrets`
|
|
2861
|
-
- `@molecule/api-two-factor`
|
|
2880
|
+
- `@molecule/api-two-factor` _(optional)_
|
|
2862
2881
|
- `express`
|
|
2863
2882
|
- `uuid`
|
|
2864
2883
|
- `zod`
|
|
@@ -2881,6 +2900,9 @@ row** — return `Props`.
|
|
|
2881
2900
|
Auth is ALREADY wired globally (the router's `verifyMiddleware` → `res.locals.session`),
|
|
2882
2901
|
so a handler reads the current user with `getUserId(res)` and does NOT add per-route auth
|
|
2883
2902
|
middleware (see the `auth` skill). Scope every custom user query by the authenticated id.
|
|
2903
|
+
The session cookie does not authenticate a write that another site started
|
|
2904
|
+
(`Sec-Fetch-Site: same-site`/`cross-site`); an app whose frontend is on another origin lists
|
|
2905
|
+
it in `APP_ORIGIN` (comma-separated) or `verifyMiddleware({ trustedOrigins })`.
|
|
2884
2906
|
|
|
2885
2907
|
**A different wire format** (RealWorld's `{ user: { … } }`): the route handlers read a
|
|
2886
2908
|
FLAT body (`req.body.username`, `req.body.password`) and are not a wire-format adapter —
|
|
@@ -2948,12 +2970,16 @@ login / signup / logout — do NOT hand-roll those against the raw routes. The r
|
|
|
2948
2970
|
client method; call them with raw `http.*`. Use these EXACT paths — a weak model guesses
|
|
2949
2971
|
`/api/auth/*` or `/api/user` (singular), and neither exists:
|
|
2950
2972
|
|
|
2951
|
-
- `POST /api/users/forgot-password` — request a reset email (body `{ email }`)
|
|
2952
|
-
|
|
2973
|
+
- `POST /api/users/forgot-password` — request a reset email (body `{ email }`) · `POST
|
|
2974
|
+
/api/users/reset-password` — confirm with the emailed token (body `{ token, password }`).
|
|
2975
|
+
A scaffold mounts these two (`emailsRouter`) only with an email provider; mounted without
|
|
2976
|
+
one, forgot-password answers 501 `user.error.passwordResetUnavailable`
|
|
2953
2977
|
- `PATCH /api/users/:id` — update profile fields (name, username, email, bio); NOT `PUT /api/user`
|
|
2954
2978
|
- `PATCH /api/users/:id/password` — change password · `DELETE /api/users/:id` — delete account
|
|
2955
2979
|
- `PATCH /api/users/:id/plan` — update the subscription plan (a paid plan with no
|
|
2956
|
-
existing subscription answers 201 `{ checkoutUrl }`; send the browser there)
|
|
2980
|
+
existing subscription answers 201 `{ checkoutUrl }`; send the browser there). This and
|
|
2981
|
+
the two payment routes below come with a payments provider (`paymentsRouter`), and
|
|
2982
|
+
`POST /api/users/:id/verify-two-factor` with a two-factor provider (`twoFactorRouter`)
|
|
2957
2983
|
- `POST /api/users/:id/verify-payment/:provider` — confirm a purchase server-side
|
|
2958
2984
|
(body/query `subscriptionId`); the provider returns the buyer to the APP's
|
|
2959
2985
|
`/plan-updated?provider=…&sessionId=…`, and THAT page calls this from the app
|
|
@@ -2964,7 +2990,8 @@ client method; call them with raw `http.*`. Use these EXACT paths — a weak mod
|
|
|
2964
2990
|
billing portal (update card, invoices, cancel); responds `{ url }`, optional body
|
|
2965
2991
|
`{ returnPath }` to come back to a specific app page. 404 `user.payment.noBillingAccount`
|
|
2966
2992
|
when the user has no customer record yet
|
|
2967
|
-
- `GET /api/users/me` — the current user (session restore)
|
|
2993
|
+
- `GET /api/users/me` — the current user `{ props, user }` (session restore), 401 when signed
|
|
2994
|
+
out · `GET /api/users/:id` — read one
|
|
2968
2995
|
The full, authoritative route list is the `routes` export (see `routes.ts`).
|
|
2969
2996
|
|
|
2970
2997
|
## E2E Tests
|
package/dist/authorization.d.ts
CHANGED
|
@@ -256,6 +256,12 @@ export interface VerifyMiddlewareOptions {
|
|
|
256
256
|
* with (`createFetchClient({ baseURL, authScheme: 'Token' })`).
|
|
257
257
|
*/
|
|
258
258
|
scheme?: string;
|
|
259
|
+
/**
|
|
260
|
+
* Origins (`https://app.example.com`) that may send cookie-authenticated writes from another
|
|
261
|
+
* site, added to the `APP_ORIGIN` / `SITE_ORIGIN` values (comma-separated) the app already
|
|
262
|
+
* sets for CORS. See {@link verifyMiddleware} for the cross-site write rule they relax.
|
|
263
|
+
*/
|
|
264
|
+
trustedOrigins?: readonly string[];
|
|
259
265
|
}
|
|
260
266
|
/**
|
|
261
267
|
* Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
@@ -273,7 +279,14 @@ export interface VerifyMiddlewareOptions {
|
|
|
273
279
|
* optional viewer with `getUserId(res)` (from `@molecule/api-bonds-default-express`, `null`
|
|
274
280
|
* when signed out), and a route that requires sign-in answers 401 itself when that is `null`,
|
|
275
281
|
* in the app's own error shape. `authorizers.auth()` is the same check as route middleware.
|
|
276
|
-
*
|
|
282
|
+
*
|
|
283
|
+
* **The cookie does not authenticate another site's writes.** A POST, PUT, PATCH or DELETE that
|
|
284
|
+
* carries only the session cookie, and that the browser labels `Sec-Fetch-Site: same-site` or
|
|
285
|
+
* `cross-site`, continues without a session (the request reaches the route signed out) unless
|
|
286
|
+
* its `Origin` is listed in `APP_ORIGIN`, `SITE_ORIGIN` or `trustedOrigins`. The app's own pages
|
|
287
|
+
* (`same-origin`), `Authorization` headers, safe methods and clients that send no
|
|
288
|
+
* `Sec-Fetch-Site` are unaffected.
|
|
289
|
+
* @param options - {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy, scheme and trusted origins.
|
|
277
290
|
* @returns An Express-compatible middleware function.
|
|
278
291
|
*/
|
|
279
292
|
export declare const verifyMiddleware: (options?: VerifyMiddlewareOptions) => MoleculeRequestHandler;
|
|
@@ -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,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AAuB,CAAA;AAEnE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,8BAA8B,sBAAsB,CAAA;AAEjE,6GAA6G;AAC7G,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,QAAQ,CAAA;AAiBnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,eAAO,MAAM,GAAG,GACd,MAAM,eAAe,EACrB,KAAK,gBAAgB,EACrB,SAAS,OAAO,KACf,MAAM,GAAG,IAuGX,CAAA;AAED,4CAA4C;AAC5C,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7F;;;;;;;;;;;;;OAaG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACnC;AAqDD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,gBAAgB,GAC1B,UAAU,uBAAuB,KAAG,sBA+HpC,CAAA"}
|
package/dist/authorization.js
CHANGED
|
@@ -518,6 +518,55 @@ export const set = (_req, res, session) => {
|
|
|
518
518
|
}
|
|
519
519
|
return null;
|
|
520
520
|
};
|
|
521
|
+
/** Methods a browser may send cross-site without changing state (RFC 9110 safe methods). */
|
|
522
|
+
const SAFE_METHODS = new Set(['GET', 'HEAD', 'OPTIONS']);
|
|
523
|
+
/**
|
|
524
|
+
* Normalize an origin string to its `scheme://host[:port]` form, or `null` when it is not one.
|
|
525
|
+
* @param value - The origin or URL text.
|
|
526
|
+
* @returns The normalized origin, or `null`.
|
|
527
|
+
*/
|
|
528
|
+
const toOrigin = (value) => {
|
|
529
|
+
try {
|
|
530
|
+
const origin = new URL(value.trim()).origin;
|
|
531
|
+
return origin === 'null' ? null : origin;
|
|
532
|
+
}
|
|
533
|
+
catch (_error) {
|
|
534
|
+
// Not an absolute URL (an empty or malformed list entry): it trusts nothing.
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
/**
|
|
539
|
+
* Whether a cookie-carried request is a write another site started (cross-site request forgery).
|
|
540
|
+
*
|
|
541
|
+
* Browsers label every request with `Sec-Fetch-Site`. A write the app's own page sends is
|
|
542
|
+
* `same-origin`; `none` is a request the user started (a typed URL). `same-site` and `cross-site`
|
|
543
|
+
* writes come from another page, which the `SameSite=Lax` session cookie does not stop when the
|
|
544
|
+
* two sites share a registrable domain (tenant apps under one parent domain), and the preview's
|
|
545
|
+
* `SameSite=None` cookie does not stop at all. Requests without the header (HTTP clients, test
|
|
546
|
+
* runners, older browsers) and safe methods keep today's behavior.
|
|
547
|
+
* @param req - The current request.
|
|
548
|
+
* @param trustedOrigins - Extra origins allowed to write with the cookie.
|
|
549
|
+
* @returns The rejected request's site and origin, or `null` when the cookie may be used.
|
|
550
|
+
*/
|
|
551
|
+
const crossSiteCookieWrite = (req, trustedOrigins) => {
|
|
552
|
+
const method = req.method?.toUpperCase();
|
|
553
|
+
if (!method || SAFE_METHODS.has(method))
|
|
554
|
+
return null;
|
|
555
|
+
const rawSite = req.headers['sec-fetch-site'];
|
|
556
|
+
const site = (Array.isArray(rawSite) ? rawSite[0] : rawSite)?.trim().toLowerCase();
|
|
557
|
+
if (!site || site === 'same-origin' || site === 'none')
|
|
558
|
+
return null;
|
|
559
|
+
const rawOrigin = req.headers.origin;
|
|
560
|
+
const origin = toOrigin((Array.isArray(rawOrigin) ? rawOrigin[0] : rawOrigin) ?? '');
|
|
561
|
+
if (origin) {
|
|
562
|
+
const configured = [getConfig('APP_ORIGIN'), getConfig('SITE_ORIGIN')]
|
|
563
|
+
.flatMap((value) => (typeof value === 'string' ? value.split(',') : []))
|
|
564
|
+
.concat(trustedOrigins ?? []);
|
|
565
|
+
if (configured.some((entry) => toOrigin(entry) === origin))
|
|
566
|
+
return null;
|
|
567
|
+
}
|
|
568
|
+
return { site, origin: origin ?? 'none' };
|
|
569
|
+
};
|
|
521
570
|
/**
|
|
522
571
|
* Middleware that verifies the JWT token from the `Authorization` header and sets `res.locals.session`.
|
|
523
572
|
* Accepts `Bearer` and `Token` (Django REST / RealWorld) plus the configured scheme, on EVERY
|
|
@@ -534,7 +583,14 @@ export const set = (_req, res, session) => {
|
|
|
534
583
|
* optional viewer with `getUserId(res)` (from `@molecule/api-bonds-default-express`, `null`
|
|
535
584
|
* when signed out), and a route that requires sign-in answers 401 itself when that is `null`,
|
|
536
585
|
* in the app's own error shape. `authorizers.auth()` is the same check as route middleware.
|
|
537
|
-
*
|
|
586
|
+
*
|
|
587
|
+
* **The cookie does not authenticate another site's writes.** A POST, PUT, PATCH or DELETE that
|
|
588
|
+
* carries only the session cookie, and that the browser labels `Sec-Fetch-Site: same-site` or
|
|
589
|
+
* `cross-site`, continues without a session (the request reaches the route signed out) unless
|
|
590
|
+
* its `Origin` is listed in `APP_ORIGIN`, `SITE_ORIGIN` or `trustedOrigins`. The app's own pages
|
|
591
|
+
* (`same-origin`), `Authorization` headers, safe methods and clients that send no
|
|
592
|
+
* `Sec-Fetch-Site` are unaffected.
|
|
593
|
+
* @param options - {@link VerifyMiddlewareOptions} controlling the auto-refresh, cookie policy, scheme and trusted origins.
|
|
538
594
|
* @returns An Express-compatible middleware function.
|
|
539
595
|
*/
|
|
540
596
|
export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
@@ -573,8 +629,16 @@ export const verifyMiddleware = (options) => async (req, res, next) => {
|
|
|
573
629
|
const headerToken = authMatch && acceptedSchemes.has(authMatch[1].toLowerCase()) ? authMatch[2].trim() : null;
|
|
574
630
|
const cookies = req.cookies;
|
|
575
631
|
const cookieToken = readAuthCookie(cookies, 'token');
|
|
576
|
-
|
|
577
|
-
|
|
632
|
+
let usableCookie = !headerToken && allowCookieSession && typeof cookieToken === 'string' && cookieToken
|
|
633
|
+
? cookieToken
|
|
634
|
+
: null;
|
|
635
|
+
const forged = usableCookie ? crossSiteCookieWrite(req, options?.trustedOrigins) : null;
|
|
636
|
+
if (forged) {
|
|
637
|
+
usableCookie = null;
|
|
638
|
+
logger.warn(`Ignored the session cookie on a ${forged.site} write from origin ${forged.origin}. ` +
|
|
639
|
+
'If that origin is this app, add it to APP_ORIGIN or verifyMiddleware({ trustedOrigins }).');
|
|
640
|
+
}
|
|
641
|
+
const token = headerToken ?? usableCookie;
|
|
578
642
|
if (!token) {
|
|
579
643
|
return next();
|
|
580
644
|
}
|
|
@@ -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,CAAC,IAAI,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA,CAAC,aAAa;IACrF,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,wEAAwE;QACxE,OAAO,IAAI,GAAG,EAAE,GAAG,EAAE,CAAA,CAAC,qBAAqB;IAC7C,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C,GAAG,aAAa,CAAA;YAC1D,8EAA8E;YAC9E,+EAA+E;YAC/E,gFAAgF;YAChF,IAAI,aAAa,KAAK,QAAQ,IAAI,WAAW,EAAE,CAAC;gBAC9C,GAAG,CAAC,MAAM,CAAC,qBAAqB,CAAC,GAAG,WAAW,CAAA;YACjD,CAAC;YAED,6CAA6C;YAC7C,IAAI,CAAC;gBACH,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAA4B,CAAA;gBACxD,IAAI,OAAO,EAAE,GAAG,EAAE,CAAC;oBACjB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CAAA;oBAChD,IACE,QAAQ,GAAG,iBAAiB,EAAE;wBAC9B,CAAC,MAAM,OAAO,EAAE,oBAAoB,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,KAAK,KAAK,EAC/D,CAAC;wBACD,8CAA8C;wBAC9C,MAAM,GAAG,CACP,QAAQ,CACT,EAAE,cAAc,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;wBAEnC,uBAAuB;wBACvB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;oBACxB,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,MAAM,EAAE,CAAC;gBAChB,sEAAsE;gBACtE,wEAAwE;gBACxE,mDAAmD;YACrD,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAA;IACpD,CAAC;IAED,OAAO,IAAI,EAAE,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -7,14 +7,16 @@ export interface ForgotPasswordRequest extends MoleculeRequest {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* Generates a
|
|
11
|
-
* email via the bonded email provider
|
|
12
|
-
*
|
|
10
|
+
* Generates a password reset token, stores its hash in the secrets table, and sends a reset
|
|
11
|
+
* email via the bonded email provider. Returns 200 whether or not the email exists, to prevent
|
|
12
|
+
* user enumeration. With no email provider bonded it returns 501
|
|
13
|
+
* `user.error.passwordResetUnavailable` for every address, since no reset email can be sent.
|
|
13
14
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
14
15
|
* @param resource.name - The resource name.
|
|
15
16
|
* @param resource.tableName - The database table name for users.
|
|
16
17
|
* @param resource.schema - Optional. Ignored — the reset flow reads and writes secrets directly.
|
|
17
|
-
* @returns A request handler that responds with `{ statusCode: 200, body: { success: true } }
|
|
18
|
+
* @returns A request handler that responds with `{ statusCode: 200, body: { success: true } }`, or
|
|
19
|
+
* 501 when no email provider is bonded.
|
|
18
20
|
*/
|
|
19
21
|
export declare const forgotPassword: ({ name: _name, tableName, schema: _schema, }: types.HandlerResource) => (req: ForgotPasswordRequest) => Promise<{
|
|
20
22
|
statusCode: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../src/handlers/forgotPassword.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAOzC,kDAAkD;AAClD,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,IAAI,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED
|
|
1
|
+
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../src/handlers/forgotPassword.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAOzC,kDAAkD;AAClD,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,IAAI,EAAE;QACJ,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,8CAI5B,KAAK,CAAC,eAAe,MACR,KAAK,qBAAqB;;;;;;;;;;;;;;EA8IzC,CAAA"}
|
|
@@ -8,14 +8,16 @@ import { normalizeEmail } from '../utilities/normalizeEmail.js';
|
|
|
8
8
|
const analytics = getAnalytics();
|
|
9
9
|
const logger = getLogger();
|
|
10
10
|
/**
|
|
11
|
-
* Generates a
|
|
12
|
-
* email via the bonded email provider
|
|
13
|
-
*
|
|
11
|
+
* Generates a password reset token, stores its hash in the secrets table, and sends a reset
|
|
12
|
+
* email via the bonded email provider. Returns 200 whether or not the email exists, to prevent
|
|
13
|
+
* user enumeration. With no email provider bonded it returns 501
|
|
14
|
+
* `user.error.passwordResetUnavailable` for every address, since no reset email can be sent.
|
|
14
15
|
* @param resource - The user resource configuration (name, tableName, schema).
|
|
15
16
|
* @param resource.name - The resource name.
|
|
16
17
|
* @param resource.tableName - The database table name for users.
|
|
17
18
|
* @param resource.schema - Optional. Ignored — the reset flow reads and writes secrets directly.
|
|
18
|
-
* @returns A request handler that responds with `{ statusCode: 200, body: { success: true } }
|
|
19
|
+
* @returns A request handler that responds with `{ statusCode: 200, body: { success: true } }`, or
|
|
20
|
+
* 501 when no email provider is bonded.
|
|
19
21
|
*/
|
|
20
22
|
export const forgotPassword = ({ name: _name, tableName, schema: _schema, }) => {
|
|
21
23
|
return async (req) => {
|
|
@@ -27,6 +29,21 @@ export const forgotPassword = ({ name: _name, tableName, schema: _schema, }) =>
|
|
|
27
29
|
body: { error: t('user.error.emailRequired'), errorKey: 'user.error.emailRequired' },
|
|
28
30
|
};
|
|
29
31
|
}
|
|
32
|
+
// With no email provider bonded no reset email can go out for ANY account, so say so
|
|
33
|
+
// instead of answering "success" and leaving the user waiting for an email that never
|
|
34
|
+
// comes. The answer is decided before the lookup, the same for every address, so it
|
|
35
|
+
// reveals nothing about which accounts exist.
|
|
36
|
+
const emailProvider = get('email');
|
|
37
|
+
if (!emailProvider) {
|
|
38
|
+
logger.warn('Password reset requested but no email provider is bonded, so no reset email can be sent. Bond an email transport (e.g. @molecule/api-emails-sendgrid) to enable password reset.');
|
|
39
|
+
return {
|
|
40
|
+
statusCode: 501,
|
|
41
|
+
body: {
|
|
42
|
+
error: t('user.error.passwordResetUnavailable'),
|
|
43
|
+
errorKey: 'user.error.passwordResetUnavailable',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
30
47
|
// Find user by email — normalized to match how signup stores it. A raw
|
|
31
48
|
// mixed-case lookup silently finds nothing, and the 200-no-reveal response
|
|
32
49
|
// (anti-enumeration) then hides the failure: the user never gets a reset.
|
|
@@ -48,58 +65,46 @@ export const forgotPassword = ({ name: _name, tableName, schema: _schema, }) =>
|
|
|
48
65
|
passwordResetToken: hashResetToken(passwordResetToken),
|
|
49
66
|
passwordResetTokenAt,
|
|
50
67
|
});
|
|
51
|
-
// Try to send email if email service is bonded.
|
|
52
68
|
try {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
const appName = getConfig('APP_NAME', 'App') ?? 'App';
|
|
70
|
+
// The site origin, or the app origin when only that one is configured: a deployment
|
|
71
|
+
// that sets just APP_ORIGIN must still get a link in the email, not a bare token.
|
|
72
|
+
const siteOrigin = getConfig('SITE_ORIGIN', '') || getConfig('APP_ORIGIN', '');
|
|
73
|
+
// The reset page prefills the address from the link: the follow-up login needs it.
|
|
74
|
+
const resetUrl = siteOrigin
|
|
75
|
+
? `${siteOrigin}/reset-password?token=${passwordResetToken}&email=${encodeURIComponent(user.email ?? email)}`
|
|
76
|
+
: '';
|
|
77
|
+
// Default the sender to the app's OWN domain (derived from SITE_ORIGIN),
|
|
78
|
+
// never a placeholder like `noreply@example.com`: a provider (e.g. Mailgun)
|
|
79
|
+
// rejects a `from` whose domain isn't its verified sending domain, so a
|
|
80
|
+
// placeholder silently BOUNCES this reset email — a critical flow. An
|
|
81
|
+
// explicit EMAIL_FROM still wins; the localhost fallback is dev-only (prod
|
|
82
|
+
// sets SITE_ORIGIN).
|
|
83
|
+
let defaultFrom = 'no-reply@localhost';
|
|
84
|
+
try {
|
|
85
|
+
if (siteOrigin)
|
|
86
|
+
defaultFrom = `no-reply@${new URL(siteOrigin).hostname}`;
|
|
61
87
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// The site origin, or the app origin when only that one is configured: a deployment
|
|
65
|
-
// that sets just APP_ORIGIN must still get a link in the email, not a bare token.
|
|
66
|
-
const siteOrigin = getConfig('SITE_ORIGIN', '') || getConfig('APP_ORIGIN', '');
|
|
67
|
-
// The reset page prefills the address from the link: the follow-up login needs it.
|
|
68
|
-
const resetUrl = siteOrigin
|
|
69
|
-
? `${siteOrigin}/reset-password?token=${passwordResetToken}&email=${encodeURIComponent(user.email ?? email)}`
|
|
70
|
-
: '';
|
|
71
|
-
// Default the sender to the app's OWN domain (derived from SITE_ORIGIN),
|
|
72
|
-
// never a placeholder like `noreply@example.com`: a provider (e.g. Mailgun)
|
|
73
|
-
// rejects a `from` whose domain isn't its verified sending domain, so a
|
|
74
|
-
// placeholder silently BOUNCES this reset email — a critical flow. An
|
|
75
|
-
// explicit EMAIL_FROM still wins; the localhost fallback is dev-only (prod
|
|
76
|
-
// sets SITE_ORIGIN).
|
|
77
|
-
let defaultFrom = 'no-reply@localhost';
|
|
78
|
-
try {
|
|
79
|
-
if (siteOrigin)
|
|
80
|
-
defaultFrom = `no-reply@${new URL(siteOrigin).hostname}`;
|
|
81
|
-
}
|
|
82
|
-
catch (_error) {
|
|
83
|
-
// Malformed SITE_ORIGIN — keep the localhost fallback.
|
|
84
|
-
}
|
|
85
|
-
await emailProvider.sendMail({
|
|
86
|
-
from: getConfig('EMAIL_FROM', defaultFrom),
|
|
87
|
-
to: email,
|
|
88
|
-
subject: t('user.email.passwordResetSubject', { appName }, { locale: user?.locale || 'en' }),
|
|
89
|
-
subjectKey: 'user.email.passwordResetSubject',
|
|
90
|
-
text: t('user.email.passwordResetText', { token: passwordResetToken }, { locale: user?.locale || 'en' }) +
|
|
91
|
-
'\n\n' +
|
|
92
|
-
(resetUrl
|
|
93
|
-
? t('user.email.passwordResetLink', { url: resetUrl }, { locale: user?.locale || 'en' })
|
|
94
|
-
: ''),
|
|
95
|
-
textKey: 'user.email.passwordResetText',
|
|
96
|
-
html: t('user.email.passwordResetHtml', { token: passwordResetToken }, { locale: user?.locale || 'en' }) +
|
|
97
|
-
(resetUrl
|
|
98
|
-
? t('user.email.passwordResetHtmlLink', { url: resetUrl }, { locale: user?.locale || 'en' })
|
|
99
|
-
: ''),
|
|
100
|
-
htmlKey: 'user.email.passwordResetHtml',
|
|
101
|
-
});
|
|
88
|
+
catch (_error) {
|
|
89
|
+
// Malformed SITE_ORIGIN — keep the localhost fallback.
|
|
102
90
|
}
|
|
91
|
+
await emailProvider.sendMail({
|
|
92
|
+
from: getConfig('EMAIL_FROM', defaultFrom),
|
|
93
|
+
to: email,
|
|
94
|
+
subject: t('user.email.passwordResetSubject', { appName }, { locale: user?.locale || 'en' }),
|
|
95
|
+
subjectKey: 'user.email.passwordResetSubject',
|
|
96
|
+
text: t('user.email.passwordResetText', { token: passwordResetToken }, { locale: user?.locale || 'en' }) +
|
|
97
|
+
'\n\n' +
|
|
98
|
+
(resetUrl
|
|
99
|
+
? t('user.email.passwordResetLink', { url: resetUrl }, { locale: user?.locale || 'en' })
|
|
100
|
+
: ''),
|
|
101
|
+
textKey: 'user.email.passwordResetText',
|
|
102
|
+
html: t('user.email.passwordResetHtml', { token: passwordResetToken }, { locale: user?.locale || 'en' }) +
|
|
103
|
+
(resetUrl
|
|
104
|
+
? t('user.email.passwordResetHtmlLink', { url: resetUrl }, { locale: user?.locale || 'en' })
|
|
105
|
+
: ''),
|
|
106
|
+
htmlKey: 'user.email.passwordResetHtml',
|
|
107
|
+
});
|
|
103
108
|
}
|
|
104
109
|
catch (error) {
|
|
105
110
|
logger.error('Failed to send password reset email:', error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forgotPassword.js","sourceRoot":"","sources":["../../src/handlers/forgotPassword.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAItC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAE/D,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;AAChC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAS1B
|
|
1
|
+
{"version":3,"file":"forgotPassword.js","sourceRoot":"","sources":["../../src/handlers/forgotPassword.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,GAAG,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AAItC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAE/D,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;AAChC,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;AAS1B;;;;;;;;;;;GAW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,CAAC,KAAK,CAAC,sDAAsD,EAAE;oBACnE,KAAK;oBACL,MAAM,EAAE,IAAI,CAAC,EAAE;iBAChB,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;YAEF,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,CAAA;QACrD,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,yCAAyC,CAAC;oBACnD,QAAQ,EAAE,yCAAyC;iBACpD;aACF,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -21,7 +21,9 @@ import type * as types from '../types.js';
|
|
|
21
21
|
* NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
22
22
|
* @param resource - The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
23
23
|
* @param resource.tableName - The database table name for users.
|
|
24
|
-
*
|
|
24
|
+
* The user comes back as both `props` and `user` (the same object), the shape sign-up and log-in
|
|
25
|
+
* answer with, so one reader serves all three.
|
|
26
|
+
* @returns A request handler responding `{ statusCode: 200, body: { props, user, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
25
27
|
*/
|
|
26
28
|
export declare const readSelf: ({ tableName }: types.HandlerResource) => (_req: MoleculeRequest, res: MoleculeResponse) => Promise<{
|
|
27
29
|
statusCode: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSelf.d.ts","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAMzC
|
|
1
|
+
{"version":3,"file":"readSelf.d.ts","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAG/E,OAAO,KAAK,KAAK,KAAK,MAAM,aAAa,CAAA;AAMzC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,QAAQ,GAAI,eAAe,KAAK,CAAC,eAAe,MAC7C,MAAM,eAAe,EAAE,KAAK,gBAAgB;;;EA8D3D,CAAA"}
|
|
@@ -26,7 +26,9 @@ const logger = getLogger();
|
|
|
26
26
|
* NEVER gets this field: exposing that token to JavaScript would defeat the cookie.
|
|
27
27
|
* @param resource - The user resource configuration: `{ name, tableName, schema? }` (`name` and `schema` are optional here).
|
|
28
28
|
* @param resource.tableName - The database table name for users.
|
|
29
|
-
*
|
|
29
|
+
* The user comes back as both `props` and `user` (the same object), the shape sign-up and log-in
|
|
30
|
+
* answer with, so one reader serves all three.
|
|
31
|
+
* @returns A request handler responding `{ statusCode: 200, body: { props, user, plan?, twoFactorEnabled?, accessToken? } }`, or 401 when unauthenticated.
|
|
30
32
|
*/
|
|
31
33
|
export const readSelf = ({ tableName }) => {
|
|
32
34
|
return async (_req, res) => {
|
|
@@ -55,7 +57,8 @@ export const readSelf = ({ tableName }) => {
|
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
59
|
const plan = await getPlan(user);
|
|
58
|
-
const
|
|
60
|
+
const props = stripSensitiveUserColumns(user);
|
|
61
|
+
const body = { props, user: props };
|
|
59
62
|
if (plan) {
|
|
60
63
|
body.plan = plan;
|
|
61
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readSelf.js","sourceRoot":"","sources":["../../src/handlers/readSelf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,M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AqD;YACvD,CAAC;YAED,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;QAClC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YACnB,OAAO;gBACL,UAAU,EAAE,GAAG;gBACf,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,6BAA6B,CAAC,EAAE,QAAQ,EAAE,6BAA6B,EAAE;aAC3F,CAAA;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -208,6 +208,9 @@
|
|
|
208
208
|
* Auth is ALREADY wired globally (the router's `verifyMiddleware` → `res.locals.session`),
|
|
209
209
|
* so a handler reads the current user with `getUserId(res)` and does NOT add per-route auth
|
|
210
210
|
* middleware (see the `auth` skill). Scope every custom user query by the authenticated id.
|
|
211
|
+
* The session cookie does not authenticate a write that another site started
|
|
212
|
+
* (`Sec-Fetch-Site: same-site`/`cross-site`); an app whose frontend is on another origin lists
|
|
213
|
+
* it in `APP_ORIGIN` (comma-separated) or `verifyMiddleware({ trustedOrigins })`.
|
|
211
214
|
*
|
|
212
215
|
* **A different wire format** (RealWorld's `{ user: { … } }`): the route handlers read a
|
|
213
216
|
* FLAT body (`req.body.username`, `req.body.password`) and are not a wire-format adapter —
|
|
@@ -274,12 +277,16 @@
|
|
|
274
277
|
* login / signup / logout — do NOT hand-roll those against the raw routes. The rest have NO
|
|
275
278
|
* client method; call them with raw `http.*`. Use these EXACT paths — a weak model guesses
|
|
276
279
|
* `/api/auth/*` or `/api/user` (singular), and neither exists:
|
|
277
|
-
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`)
|
|
278
|
-
*
|
|
280
|
+
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`) · `POST
|
|
281
|
+
* /api/users/reset-password` — confirm with the emailed token (body `{ token, password }`).
|
|
282
|
+
* A scaffold mounts these two (`emailsRouter`) only with an email provider; mounted without
|
|
283
|
+
* one, forgot-password answers 501 `user.error.passwordResetUnavailable`
|
|
279
284
|
* - `PATCH /api/users/:id` — update profile fields (name, username, email, bio); NOT `PUT /api/user`
|
|
280
285
|
* - `PATCH /api/users/:id/password` — change password · `DELETE /api/users/:id` — delete account
|
|
281
286
|
* - `PATCH /api/users/:id/plan` — update the subscription plan (a paid plan with no
|
|
282
|
-
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there)
|
|
287
|
+
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there). This and
|
|
288
|
+
* the two payment routes below come with a payments provider (`paymentsRouter`), and
|
|
289
|
+
* `POST /api/users/:id/verify-two-factor` with a two-factor provider (`twoFactorRouter`)
|
|
283
290
|
* - `POST /api/users/:id/verify-payment/:provider` — confirm a purchase server-side
|
|
284
291
|
* (body/query `subscriptionId`); the provider returns the buyer to the APP's
|
|
285
292
|
* `/plan-updated?provider=…&sessionId=…`, and THAT page calls this from the app
|
|
@@ -290,11 +297,16 @@
|
|
|
290
297
|
* billing portal (update card, invoices, cancel); responds `{ url }`, optional body
|
|
291
298
|
* `{ returnPath }` to come back to a specific app page. 404 `user.payment.noBillingAccount`
|
|
292
299
|
* when the user has no customer record yet
|
|
293
|
-
* - `GET /api/users/me` — the current user (session restore)
|
|
300
|
+
* - `GET /api/users/me` — the current user `{ props, user }` (session restore), 401 when signed
|
|
301
|
+
* out · `GET /api/users/:id` — read one
|
|
294
302
|
* The full, authoritative route list is the `routes` export (see `routes.ts`).
|
|
295
303
|
*
|
|
296
304
|
* @example
|
|
297
305
|
* ```ts
|
|
306
|
+
* // The routes it mounts (under /api) answer:
|
|
307
|
+
* // POST /users, POST /users/log-in → { props, accessToken, user }; bad credentials → 403, not 401
|
|
308
|
+
* // GET /users/me → { props, user }; signed out → 401
|
|
309
|
+
*
|
|
298
310
|
* // Extend safely: a display field in Props, a secret in SecretProps.
|
|
299
311
|
* // propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
300
312
|
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6VG;AAEH,cAAc,eAAe,CAAA;AAC7B,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,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,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
|
@@ -208,6 +208,9 @@
|
|
|
208
208
|
* Auth is ALREADY wired globally (the router's `verifyMiddleware` → `res.locals.session`),
|
|
209
209
|
* so a handler reads the current user with `getUserId(res)` and does NOT add per-route auth
|
|
210
210
|
* middleware (see the `auth` skill). Scope every custom user query by the authenticated id.
|
|
211
|
+
* The session cookie does not authenticate a write that another site started
|
|
212
|
+
* (`Sec-Fetch-Site: same-site`/`cross-site`); an app whose frontend is on another origin lists
|
|
213
|
+
* it in `APP_ORIGIN` (comma-separated) or `verifyMiddleware({ trustedOrigins })`.
|
|
211
214
|
*
|
|
212
215
|
* **A different wire format** (RealWorld's `{ user: { … } }`): the route handlers read a
|
|
213
216
|
* FLAT body (`req.body.username`, `req.body.password`) and are not a wire-format adapter —
|
|
@@ -274,12 +277,16 @@
|
|
|
274
277
|
* login / signup / logout — do NOT hand-roll those against the raw routes. The rest have NO
|
|
275
278
|
* client method; call them with raw `http.*`. Use these EXACT paths — a weak model guesses
|
|
276
279
|
* `/api/auth/*` or `/api/user` (singular), and neither exists:
|
|
277
|
-
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`)
|
|
278
|
-
*
|
|
280
|
+
* - `POST /api/users/forgot-password` — request a reset email (body `{ email }`) · `POST
|
|
281
|
+
* /api/users/reset-password` — confirm with the emailed token (body `{ token, password }`).
|
|
282
|
+
* A scaffold mounts these two (`emailsRouter`) only with an email provider; mounted without
|
|
283
|
+
* one, forgot-password answers 501 `user.error.passwordResetUnavailable`
|
|
279
284
|
* - `PATCH /api/users/:id` — update profile fields (name, username, email, bio); NOT `PUT /api/user`
|
|
280
285
|
* - `PATCH /api/users/:id/password` — change password · `DELETE /api/users/:id` — delete account
|
|
281
286
|
* - `PATCH /api/users/:id/plan` — update the subscription plan (a paid plan with no
|
|
282
|
-
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there)
|
|
287
|
+
* existing subscription answers 201 `{ checkoutUrl }`; send the browser there). This and
|
|
288
|
+
* the two payment routes below come with a payments provider (`paymentsRouter`), and
|
|
289
|
+
* `POST /api/users/:id/verify-two-factor` with a two-factor provider (`twoFactorRouter`)
|
|
283
290
|
* - `POST /api/users/:id/verify-payment/:provider` — confirm a purchase server-side
|
|
284
291
|
* (body/query `subscriptionId`); the provider returns the buyer to the APP's
|
|
285
292
|
* `/plan-updated?provider=…&sessionId=…`, and THAT page calls this from the app
|
|
@@ -290,11 +297,16 @@
|
|
|
290
297
|
* billing portal (update card, invoices, cancel); responds `{ url }`, optional body
|
|
291
298
|
* `{ returnPath }` to come back to a specific app page. 404 `user.payment.noBillingAccount`
|
|
292
299
|
* when the user has no customer record yet
|
|
293
|
-
* - `GET /api/users/me` — the current user (session restore)
|
|
300
|
+
* - `GET /api/users/me` — the current user `{ props, user }` (session restore), 401 when signed
|
|
301
|
+
* out · `GET /api/users/:id` — read one
|
|
294
302
|
* The full, authoritative route list is the `routes` export (see `routes.ts`).
|
|
295
303
|
*
|
|
296
304
|
* @example
|
|
297
305
|
* ```ts
|
|
306
|
+
* // The routes it mounts (under /api) answer:
|
|
307
|
+
* // POST /users, POST /users/log-in → { props, accessToken, user }; bad credentials → 403, not 401
|
|
308
|
+
* // GET /users/me → { props, user }; signed out → 401
|
|
309
|
+
*
|
|
298
310
|
* // Extend safely: a display field in Props, a secret in SecretProps.
|
|
299
311
|
* // propsSchema: { …, timezone: z.string().optional() } // safe → client
|
|
300
312
|
* // secretPropsSchema: { …, passwordResetToken: z.string().optional() } // server-only, usersSecrets
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6VG;AAEH,cAAc,eAAe,CAAA;AAC7B,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,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,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/routes.d.ts
CHANGED
|
@@ -40,5 +40,11 @@ export declare const routes: ({
|
|
|
40
40
|
middlewares: string[];
|
|
41
41
|
handler: string;
|
|
42
42
|
optional?: undefined;
|
|
43
|
+
} | {
|
|
44
|
+
method: "patch";
|
|
45
|
+
path: string;
|
|
46
|
+
middlewares: string[];
|
|
47
|
+
handler: string;
|
|
48
|
+
optional: string;
|
|
43
49
|
})[];
|
|
44
50
|
//# sourceMappingURL=routes.d.ts.map
|
package/dist/routes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,MAAM
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwIlB,CAAA"}
|
package/dist/routes.js
CHANGED
|
@@ -42,17 +42,21 @@ export const routes = [
|
|
|
42
42
|
// `:id`. [M1-1] under the in-memory-token model logout MUST clear the httpOnly
|
|
43
43
|
// cookie, else cookie-restore re-logs-in on the next load.
|
|
44
44
|
{ method: 'post', path: '/users/logout', middlewares: ['auth'], handler: 'logout' },
|
|
45
|
+
// Password reset by email — the reset link is sent by the bonded email transport, so
|
|
46
|
+
// these routes come with one ('emails'): without it forgot-password can only answer 501.
|
|
45
47
|
{
|
|
46
48
|
method: 'post',
|
|
47
49
|
path: '/users/forgot-password',
|
|
48
50
|
middlewares: ['rateLimitAuth'],
|
|
49
51
|
handler: 'forgotPassword',
|
|
52
|
+
optional: 'emails',
|
|
50
53
|
},
|
|
51
54
|
{
|
|
52
55
|
method: 'post',
|
|
53
56
|
path: '/users/reset-password',
|
|
54
57
|
middlewares: ['rateLimitAuth'],
|
|
55
58
|
handler: 'resetPassword',
|
|
59
|
+
optional: 'emails',
|
|
56
60
|
},
|
|
57
61
|
// Current user — session restore. MUST precede `/users/:id` so `me` isn't
|
|
58
62
|
// matched as an `:id`. Cookie-authed (`auth`, not `authSelf` — there is no
|
|
@@ -76,6 +80,8 @@ export const routes = [
|
|
|
76
80
|
path: '/users/:id/verify-two-factor',
|
|
77
81
|
middlewares: ['authSelf', 'rateLimitTwoFactor'],
|
|
78
82
|
handler: 'verifyTwoFactor',
|
|
83
|
+
// Set-up and checks go through the bonded two-factor provider (@molecule/api-two-factor).
|
|
84
|
+
optional: 'two-factor',
|
|
79
85
|
},
|
|
80
86
|
// Plans
|
|
81
87
|
{
|
|
@@ -83,6 +89,7 @@ export const routes = [
|
|
|
83
89
|
path: '/users/:id/plan',
|
|
84
90
|
middlewares: ['authSelf'],
|
|
85
91
|
handler: 'updatePlan',
|
|
92
|
+
optional: 'payments',
|
|
86
93
|
},
|
|
87
94
|
// Payment verification — GET (redirect callbacks, e.g. Stripe Checkout). [M3-1]
|
|
88
95
|
// authSelf like the POST + molecule-dev's router: the plan is granted to `:id` and the
|
package/dist/routes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routes.js","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,OAAO;IACP,EAAE,MAAM,EAAE,MAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;IAC/E;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,CAAC,eAAe,CAAC;QAC9B,OAAO,EAAE,OAAO;KACjB;IACD,0EAA0E;IAC1E,2EAA2E;IAC3E,2EAA2E;IAC3E,wDAAwD;IACxD,EAAE;IACF,yEAAyE;IACzE,yEAAyE;IACzE,qEAAqE;IACrE,yEAAyE;IACzE,2EAA2E;IAC3E;QACE,MAAM,EAAE,KAAc;QACtB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,CAAC,eAAe,CAAC;QAC9B,OAAO,EAAE,gBAAgB;QACzB,QAAQ,EAAE,OAAO;KAClB;IACD;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,qBAAqB;QAC3B,WAAW,EAAE,CAAC,eAAe,CAAC;QAC9B,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE,OAAO;KAClB;IACD,+EAA+E;IAC/E,+EAA+E;IAC/E,+EAA+E;IAC/E,2DAA2D;IAC3D,EAAE,MAAM,EAAE,MAAe,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE;IAC5F;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAA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IAED,gFAAgF;IAChF,uFAAuF;IACvF,uFAAuF;IACvF,wFAAwF;IACxF,+DAA+D;IAC/D;QACE,MAAM,EAAE,KAAc;QACtB,IAAI,EAAE,qCAAqC;QAC3C,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,OAAO,EAAE,eAAe;QACxB,QAAQ,EAAE,UAAU;KACrB;IACD,0EAA0E;IAC1E,0EAA0E;IAC1E,6EAA6E;IAC7E;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,qCAAqC;QAC3C,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,OAAO,EAAE,eAAe;QACxB,QAAQ,EAAE,UAAU;KACrB;IACD,0EAA0E;IAC1E,2EAA2E;IAC3E,4EAA4E;IAC5E,6DAA6D;IAC7D;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,qCAAqC;QAC3C,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,OAAO,EAAE,eAAe;QACxB,QAAQ,EAAE,UAAU;KACrB;IACD,qEAAqE;IACrE,+EAA+E;IAC/E,8EAA8E;IAC9E,mCAAmC;IACnC;QACE,MAAM,EAAE,MAAe;QACvB,IAAI,EAAE,uCAAuC;QAC7C,WAAW,EAAE,CAAC,4BAA4B,CAAC;QAC3C,OAAO,EAAE,2BAA2B;QACpC,QAAQ,EAAE,UAAU;KACrB;CACF,CAAA"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
declare const router: import("express-serve-static-core").Router;
|
|
2
2
|
/** OAuth initiation and credential exchange routes. */
|
|
3
3
|
export declare const oauthRouter: import("express-serve-static-core").Router;
|
|
4
|
-
/**
|
|
4
|
+
/** Password reset by email: the bonded email transport sends the reset link. */
|
|
5
|
+
export declare const emailsRouter: import("express-serve-static-core").Router;
|
|
6
|
+
/** Two-factor set-up, enabling and disabling, checked by the bonded two-factor provider. */
|
|
7
|
+
export declare const twoFactorRouter: import("express-serve-static-core").Router;
|
|
8
|
+
/** Plan changes, authenticated billing routes and the provider webhook. */
|
|
5
9
|
export declare const paymentsRouter: import("express-serve-static-core").Router;
|
|
6
10
|
export default router;
|
|
7
11
|
//# sourceMappingURL=scaffold-router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-router.d.ts","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM,4CAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"scaffold-router.d.ts","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,MAAM,4CAAW,CAAA;AAyCvB,uDAAuD;AACvD,eAAO,MAAM,WAAW,4CAAW,CAAA;AAYnC,gFAAgF;AAChF,eAAO,MAAM,YAAY,4CAAW,CAAA;AAYpC,4FAA4F;AAC5F,eAAO,MAAM,eAAe,4CAAW,CAAA;AAQvC,2EAA2E;AAC3E,eAAO,MAAM,cAAc,4CAAW,CAAA;AAoBtC,eAAe,MAAM,CAAA"}
|
package/dist/scaffold-router.js
CHANGED
|
@@ -26,23 +26,27 @@ router.post('/users/log-in', rateLimitAuth, async (req, res) => {
|
|
|
26
26
|
res.status(result.statusCode).json(result.body);
|
|
27
27
|
});
|
|
28
28
|
router.post('/users/logout', auth, createRequestHandler(handlers.logout()));
|
|
29
|
-
router.post('/users/forgot-password', rateLimitAuth, createRequestHandler(handlers.forgotPassword(resource)));
|
|
30
|
-
router.post('/users/reset-password', rateLimitAuth, createRequestHandler(handlers.resetPassword(resource)));
|
|
31
29
|
// Keep current-user lookup before the parameterized route.
|
|
32
30
|
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)));
|
|
33
31
|
router.get('/users/:id', authSelf, createRequestHandler(handlers.read(resource)));
|
|
34
32
|
router.patch('/users/:id', authSelf, createRequestHandler(handlers.update(resource)));
|
|
35
33
|
router.delete('/users/:id', authSelf, createRequestHandler(handlers.del(resource)));
|
|
36
34
|
router.patch('/users/:id/password', authSelf, createRequestHandler(handlers.updatePassword(resource)));
|
|
37
|
-
router.post('/users/:id/verify-two-factor', authSelf, rateLimitTwoFactor, createRequestHandler(handlers.verifyTwoFactor(resource)));
|
|
38
|
-
router.patch('/users/:id/plan', authSelf, createRequestHandler(handlers.updatePlan(resource)));
|
|
39
35
|
// Feature routers are mounted by the app when the corresponding provider is installed.
|
|
40
36
|
/** OAuth initiation and credential exchange routes. */
|
|
41
37
|
export const oauthRouter = Router();
|
|
42
38
|
oauthRouter.get('/users/oauth/:provider', rateLimitAuth, createRequestHandler(handlers.oauthAuthorize()));
|
|
43
39
|
oauthRouter.post('/users/log-in/oauth', rateLimitAuth, createRequestHandler(handlers.logInOAuth(resource)));
|
|
44
|
-
/**
|
|
40
|
+
/** Password reset by email: the bonded email transport sends the reset link. */
|
|
41
|
+
export const emailsRouter = Router();
|
|
42
|
+
emailsRouter.post('/users/forgot-password', rateLimitAuth, createRequestHandler(handlers.forgotPassword(resource)));
|
|
43
|
+
emailsRouter.post('/users/reset-password', rateLimitAuth, createRequestHandler(handlers.resetPassword(resource)));
|
|
44
|
+
/** Two-factor set-up, enabling and disabling, checked by the bonded two-factor provider. */
|
|
45
|
+
export const twoFactorRouter = Router();
|
|
46
|
+
twoFactorRouter.post('/users/:id/verify-two-factor', authSelf, rateLimitTwoFactor, createRequestHandler(handlers.verifyTwoFactor(resource)));
|
|
47
|
+
/** Plan changes, authenticated billing routes and the provider webhook. */
|
|
45
48
|
export const paymentsRouter = Router();
|
|
49
|
+
paymentsRouter.patch('/users/:id/plan', authSelf, createRequestHandler(handlers.updatePlan(resource)));
|
|
46
50
|
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource));
|
|
47
51
|
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment);
|
|
48
52
|
paymentsRouter.post('/users/:id/verify-payment/:provider', authSelf, verifyPayment);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold-router.js","sourceRoot":"","sources":["../src/scaffold-router.ts"],"names":[],"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AC,GAAG,CAAC,qCAAqC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAA;AAClF,cAAc,CAAC,IAAI,CAAC,qCAAqC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAA;AACnF,cAAc,CAAC,IAAI,CACjB,qCAAqC,EACrC,QAAQ,EACR,oBAAoB,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAC/C,CAAA;AACD,cAAc,CAAC,IAAI,CACjB,uCAAuC,EACvC,WAAW,CAAC,0BAA0B,EAAE,EACxC,oBAAoB,CAAC,QAAQ,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CACnE,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-resource-user",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.2",
|
|
4
4
|
"description": "User registration, login, JWT sessions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@molecule/api-bond": "1.0.4",
|
|
38
38
|
"@molecule/api-config": "1.0.4",
|
|
39
|
-
"@molecule/api-locales-user": "1.1
|
|
39
|
+
"@molecule/api-locales-user": "1.2.1",
|
|
40
40
|
"@molecule/api-locales-user-payments": "1.0.5",
|
|
41
41
|
"@molecule/api-payments": "1.2.3",
|
|
42
42
|
"@molecule/api-push-notifications": "1.2.0",
|
package/src/scaffold-router.ts
CHANGED
|
@@ -31,16 +31,6 @@ router.post('/users/log-in', rateLimitAuth, async (req, res) => {
|
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
router.post('/users/logout', auth, createRequestHandler(handlers.logout()))
|
|
34
|
-
router.post(
|
|
35
|
-
'/users/forgot-password',
|
|
36
|
-
rateLimitAuth,
|
|
37
|
-
createRequestHandler(handlers.forgotPassword(resource)),
|
|
38
|
-
)
|
|
39
|
-
router.post(
|
|
40
|
-
'/users/reset-password',
|
|
41
|
-
rateLimitAuth,
|
|
42
|
-
createRequestHandler(handlers.resetPassword(resource)),
|
|
43
|
-
)
|
|
44
34
|
|
|
45
35
|
// Keep current-user lookup before the parameterized route.
|
|
46
36
|
router.get('/users/me', auth, createRequestHandler(handlers.readSelf(resource)))
|
|
@@ -52,13 +42,6 @@ router.patch(
|
|
|
52
42
|
authSelf,
|
|
53
43
|
createRequestHandler(handlers.updatePassword(resource)),
|
|
54
44
|
)
|
|
55
|
-
router.post(
|
|
56
|
-
'/users/:id/verify-two-factor',
|
|
57
|
-
authSelf,
|
|
58
|
-
rateLimitTwoFactor,
|
|
59
|
-
createRequestHandler(handlers.verifyTwoFactor(resource)),
|
|
60
|
-
)
|
|
61
|
-
router.patch('/users/:id/plan', authSelf, createRequestHandler(handlers.updatePlan(resource)))
|
|
62
45
|
|
|
63
46
|
// Feature routers are mounted by the app when the corresponding provider is installed.
|
|
64
47
|
/** OAuth initiation and credential exchange routes. */
|
|
@@ -74,8 +57,35 @@ oauthRouter.post(
|
|
|
74
57
|
createRequestHandler(handlers.logInOAuth(resource)),
|
|
75
58
|
)
|
|
76
59
|
|
|
77
|
-
/**
|
|
60
|
+
/** Password reset by email: the bonded email transport sends the reset link. */
|
|
61
|
+
export const emailsRouter = Router()
|
|
62
|
+
emailsRouter.post(
|
|
63
|
+
'/users/forgot-password',
|
|
64
|
+
rateLimitAuth,
|
|
65
|
+
createRequestHandler(handlers.forgotPassword(resource)),
|
|
66
|
+
)
|
|
67
|
+
emailsRouter.post(
|
|
68
|
+
'/users/reset-password',
|
|
69
|
+
rateLimitAuth,
|
|
70
|
+
createRequestHandler(handlers.resetPassword(resource)),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
/** Two-factor set-up, enabling and disabling, checked by the bonded two-factor provider. */
|
|
74
|
+
export const twoFactorRouter = Router()
|
|
75
|
+
twoFactorRouter.post(
|
|
76
|
+
'/users/:id/verify-two-factor',
|
|
77
|
+
authSelf,
|
|
78
|
+
rateLimitTwoFactor,
|
|
79
|
+
createRequestHandler(handlers.verifyTwoFactor(resource)),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
/** Plan changes, authenticated billing routes and the provider webhook. */
|
|
78
83
|
export const paymentsRouter = Router()
|
|
84
|
+
paymentsRouter.patch(
|
|
85
|
+
'/users/:id/plan',
|
|
86
|
+
authSelf,
|
|
87
|
+
createRequestHandler(handlers.updatePlan(resource)),
|
|
88
|
+
)
|
|
79
89
|
const verifyPayment = createRequestHandler(handlers.verifyPayment(resource))
|
|
80
90
|
paymentsRouter.get('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|
|
81
91
|
paymentsRouter.post('/users/:id/verify-payment/:provider', authSelf, verifyPayment)
|