@molecule/app-auth-modal-solid 0.0.1-stage → 1.1.0

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.
Files changed (2) hide show
  1. package/README.md +282 -4
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,11 +1,289 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-21T12:46:15.293Z
7
+ -->
8
+
1
9
  # @molecule/app-auth-modal-solid
2
10
 
3
- In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work
11
+ `@molecule/app-auth-modal-solid` — the shared in-app login / signup /
12
+ upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
13
+ providers (where the `@molecule/app-solid` auth primitives work) and every
14
+ in-app `/login` / `/signup` link opens the {@link AuthModal} instead of
15
+ navigating, while `/pricing` / `/billing` links open the upgrade flow in
16
+ a new tab (session auto-refreshes when the user returns) — no
17
+ navigation, no reload, no lost work. OAuth runs in a popup
18
+ (`loginViaPopup`), so social login never navigates the host either.
19
+
20
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
21
+ > It is written to be read by coding agents as much as by people, and is generated from this
22
+ > package's source — edit `src/index.ts` JSDoc, not this file.
23
+
24
+ ## Quick Start
25
+
26
+ ```tsx
27
+ import { render } from 'solid-js/web'
28
+ import { AuthModalMount } from '@molecule/app-auth-modal-solid'
29
+ import { oauthConfig } from './config.jsx'
30
+
31
+ // Once, inside the app's providers (e.g. in App.tsx):
32
+ ;<AuthModalMount oauthConfig={oauthConfig} onAuthenticated={() => claimGuestWork()} />
33
+ // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
34
+ // anywhere in the app is now intercepted — no other wiring needed.
35
+ ```
36
+
37
+ ## Type
38
+
39
+ `feature`
40
+
41
+ ## Installation
42
+
43
+ ```bash
44
+ npm install @molecule/app-auth-modal-solid @molecule/app-auth-shell-solid @molecule/app-i18n @molecule/app-oauth-buttons-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js
45
+ ```
46
+
47
+ ## API
48
+
49
+ ### Interfaces
50
+
51
+ #### `AuthModalProps`
52
+
53
+ Props for {@link AuthModal}.
54
+
55
+ ```typescript
56
+ interface AuthModalProps {
57
+ /** Whether the modal is open. */
58
+ open: boolean
59
+ /** Close without authenticating (backdrop / Escape / ✕). */
60
+ onClose?: () => void
61
+ /** Which form to open on. Defaults to `'signup'`. */
62
+ initialMode?: AuthModalMode
63
+ /**
64
+ * OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
65
+ * from the app's `config.ts`. Drives the popup OAuth buttons.
66
+ */
67
+ oauthConfig: UseOAuthConfig
68
+ /**
69
+ * Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the guest
70
+ * id so the new session can claim its work. Optional.
71
+ */
72
+ onBeforeAuth?: () => void
73
+ /**
74
+ * Run AFTER a successful login/signup/OAuth (the session is already refreshed),
75
+ * still on the same page — e.g. claim guest projects, invalidate usage. Optional.
76
+ */
77
+ onAuthenticated?: () => void | Promise<void>
78
+ /**
79
+ * A human-verification challenge rendered inside the SIGNUP form, above the
80
+ * submit button (e.g. the app's Turnstile/hCaptcha widget). Login is not
81
+ * gated, so the slot is unmounted in login mode — which lets the widget clear
82
+ * its own token when the user switches tabs and re-issue a fresh one on the
83
+ * way back.
84
+ *
85
+ * The modal stays provider-agnostic: it renders the node and never inspects
86
+ * it. An app whose signup API requires a challenge MUST pass
87
+ * {@link AuthModalProps.captchaSolved} as well, or the form will submit
88
+ * without a token and the API will reject it.
89
+ *
90
+ * Optional — omitted (the default for apps with no challenge) the signup form
91
+ * is unchanged.
92
+ */
93
+ captchaSlot?: JSX.Element
94
+ /**
95
+ * Whether the {@link AuthModalProps.captchaSlot} challenge is currently
96
+ * solved. `false` disables the signup submit, so the form cannot POST a
97
+ * missing/expired token. Defaults to `true` (no challenge → nothing to wait
98
+ * for). Ignored in login mode.
99
+ */
100
+ captchaSolved?: boolean
101
+ }
102
+ ```
103
+
104
+ #### `AuthModalMountProps`
105
+
106
+ Props for {@link AuthModalMount}.
107
+
108
+ ```typescript
109
+ interface AuthModalMountProps {
110
+ /** OAuth config from the app's `config.ts` (drives the popup OAuth buttons). */
111
+ oauthConfig: AuthModalProps['oauthConfig']
112
+ /** Run before any login attempt (e.g. stash the guest id). Optional. */
113
+ onBeforeAuth?: () => void
114
+ /** Run after a successful login (session already refreshed). Optional. */
115
+ onAuthenticated?: () => void | Promise<void>
116
+ /**
117
+ * Run when the user returns to this tab after the upgrade tab (the session is
118
+ * already refreshed here) — e.g. invalidate usage so a budget banner clears.
119
+ * Only fires for the default new-tab flow; irrelevant when
120
+ * {@link AuthModalMountProps.onUpgradeIntercept} is set. Optional.
121
+ */
122
+ onUpgradeReturn?: () => void
123
+ /**
124
+ * Take over upgrade/billing CTA clicks instead of opening a new tab: called
125
+ * with the matched upgrade path (e.g. `/pricing`), navigation already
126
+ * prevented. The host renders its own upgrade UI (typically a modal) and owns
127
+ * refreshing the session when that flow completes. Optional — when omitted,
128
+ * the default new-tab flow (+ focus-return refresh) applies.
129
+ */
130
+ onUpgradeIntercept?: (path: string) => void
131
+ /**
132
+ * Human-verification challenge rendered inside the modal's SIGNUP form — see
133
+ * {@link AuthModalProps.captchaSlot}. Pass it together with
134
+ * {@link AuthModalMountProps.captchaSolved} whenever the app's signup API
135
+ * requires a challenge token, otherwise the in-app signup POSTs without one
136
+ * while the standalone `/signup` page (which renders its own widget) works —
137
+ * a mismatch the user experiences as "complete the challenge" with no
138
+ * challenge on screen. Optional.
139
+ */
140
+ captchaSlot?: AuthModalProps['captchaSlot']
141
+ /** Whether {@link AuthModalMountProps.captchaSlot} is solved; `false` disables the signup submit. Defaults to `true`. */
142
+ captchaSolved?: boolean
143
+ /** Override the auth path→mode map (defaults to `/login`,`/signup`). */
144
+ authPaths?: Readonly<Record<string, AuthModalMode>>
145
+ /** Override the upgrade paths opened in a new tab (defaults to `/pricing`,`/billing`). */
146
+ upgradePaths?: readonly string[]
147
+ }
148
+ ```
149
+
150
+ ### Types
151
+
152
+ #### `AuthModalMode`
153
+
154
+ Which form {@link AuthModal} should show.
155
+
156
+ ```typescript
157
+ type AuthModalMode = 'login' | 'signup'
158
+ ```
159
+
160
+ ### Functions
161
+
162
+ #### `AuthModal(props)`
163
+
164
+ The in-app auth modal: login/signup tabs rendered in a Modal overlay — the user authenticates without leaving the current page (no navigation, no lost work). Usually rendered via `AuthModalMount`, not directly.
165
+
166
+ ```typescript
167
+ function AuthModal(props: AuthModalProps): JSX.Element
168
+ ```
169
+
170
+ - `props` — {@link AuthModalProps}.
4
171
 
172
+ **Returns:** The modal element (renders nothing when closed).
173
+
174
+ #### `AuthModalMount(props)`
175
+
176
+ Mounts the in-app auth modal + the CTA click-interceptor: renders the (initially hidden) AuthModal and installs a capture-phase document click handler that opens it for in-app `/login`/`/signup` links (and routes `/pricing`/`/billing` clicks to the upgrade flow). Mount ONCE inside the app providers.
177
+
178
+ ```typescript
179
+ function AuthModalMount(props: AuthModalMountProps): JSX.Element
180
+ ```
181
+
182
+ - `props` — {@link AuthModalMountProps}.
183
+
184
+ **Returns:** The (lazily-mounted) auth modal element.
185
+
186
+ #### `authModeForHref(href, origin, authPaths)`
187
+
188
+ Map a CTA link's href to the auth mode it should open, or `null` if it is not
189
+ an auth link (so the interceptor leaves it alone).
190
+
191
+ ```typescript
192
+ function authModeForHref(
193
+ href: string | null | undefined,
194
+ origin: string,
195
+ authPaths?: Readonly<Record<string, AuthModalMode>>,
196
+ ): AuthModalMode | null
197
+ ```
198
+
199
+ - `href` — The clicked anchor's href (relative or absolute).
200
+ - `origin` — The page origin to resolve a relative href against.
201
+ - `authPaths` — Path→mode map (defaults to {@link DEFAULT_AUTH_PATHS}).
202
+
203
+ **Returns:** `'login'` / `'signup'`, else `null`.
204
+
205
+ #### `upgradePathForHref(href, origin, upgradePaths)`
206
+
207
+ Whether a CTA link's href points at the upgrade/billing flow (which the
208
+ interceptor hands to the host's `onUpgradeIntercept`, else opens in a new tab).
209
+
210
+ ```typescript
211
+ function upgradePathForHref(
212
+ href: string | null | undefined,
213
+ origin: string,
214
+ upgradePaths?: readonly string[],
215
+ ): string | null
216
+ ```
217
+
218
+ - `href` — The clicked anchor's href (relative or absolute).
219
+ - `origin` — The page origin to resolve a relative href against.
220
+ - `upgradePaths` — The upgrade paths (defaults to {@link DEFAULT_UPGRADE_PATHS}).
221
+
222
+ **Returns:** The matched pathname, else `null`.
223
+
224
+ ### Constants
225
+
226
+ #### `DEFAULT_AUTH_PATHS`
227
+
228
+ The default in-app auth routes that open the modal.
229
+
230
+ ```typescript
231
+ const DEFAULT_AUTH_PATHS: Readonly<Record<string, AuthModalMode>>
5
232
  ```
6
- npm install @molecule/app-auth-modal-solid
233
+
234
+ #### `DEFAULT_UPGRADE_PATHS`
235
+
236
+ The default routes that open the upgrade/billing flow (modal or new tab).
237
+
238
+ ```typescript
239
+ const DEFAULT_UPGRADE_PATHS: readonly string[]
7
240
  ```
8
241
 
9
- Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
242
+ ## Injection Notes
243
+
244
+ ### Requirements
245
+
246
+ Peer dependencies:
247
+
248
+ - `@molecule/app-auth-shell-solid` ^1.0.0
249
+ - `@molecule/app-i18n` ^1.0.1
250
+ - `@molecule/app-oauth-buttons-solid` ^1.0.0
251
+ - `@molecule/app-solid` ^3.5.0
252
+ - `@molecule/app-ui` ^1.0.1
253
+ - `@molecule/app-ui-solid` ^1.1.0
254
+ - `solid-js` ^1.8.0
255
+
256
+ ### Runtime Dependencies
257
+
258
+ - `@molecule/app-auth-shell-solid`
259
+ - `@molecule/app-i18n`
260
+ - `@molecule/app-oauth-buttons-solid`
261
+ - `@molecule/app-solid`
262
+ - `@molecule/app-ui`
263
+ - `@molecule/app-ui-solid`
264
+ - `solid-js`
265
+
266
+ Interception is capture-phase on `document` and matches plain
267
+ left-clicks on `<a href>` whose resolved pathname is in `authPaths`
268
+ (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
269
+ `/billing`) — modifier/middle clicks still navigate normally, and
270
+ non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
271
+ that render pricing in-place pass `onUpgradeIntercept` and own that UI
272
+
273
+ - the post-upgrade session refresh. `AuthModalMount` must render inside
274
+ the app's auth/HTTP providers (it calls `useAuth`), and the standalone
275
+ `/login` & `/signup` pages should stay routed — they are the fallback
276
+ for modifier clicks and deep links. App-specific extras (stash a guest
277
+ id, claim guest work, invalidate usage) go in `onBeforeAuth` /
278
+ `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
279
+ `@molecule/app-locales-common` bond (79 languages), alongside the
280
+ `auth.login.*` / `auth.signup.*` keys the modal also renders.
10
281
 
11
- License: Apache-2.0
282
+ If the signup API requires a human-verification challenge (Turnstile /
283
+ hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
284
+ form) and `captchaSolved` (which gates the submit). Rendering the widget
285
+ on the standalone `/signup` page alone is NOT enough: this modal is what
286
+ a `/signup` link actually opens, so the in-app signup would POST with no
287
+ token and the API would answer "complete the verification challenge"
288
+ while no challenge is on screen. Login is not gated, so the slot is
289
+ unmounted in login mode.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-auth-modal-solid",
3
- "version": "0.0.1-stage",
3
+ "version": "1.1.0",
4
4
  "description": "In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work",
5
5
  "homepage": "https://www.molecule.dev/packages/app-auth-modal-solid",
6
6
  "type": "module",
@@ -55,14 +55,14 @@
55
55
  "solid-js": "^1.8.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@molecule/app-auth-shell-solid": "1.0.0",
58
+ "@molecule/app-auth-shell-solid": "1.1.0",
59
59
  "@molecule/app-framework-conformance": "0.0.0",
60
60
  "@molecule/app-i18n": "1.2.2",
61
61
  "@molecule/app-icons": "1.0.4",
62
62
  "@molecule/app-oauth-buttons-solid": "1.2.0",
63
- "@molecule/app-solid": "3.7.2",
64
- "@molecule/app-ui": "1.4.0",
65
- "@molecule/app-ui-solid": "1.1.5",
63
+ "@molecule/app-solid": "3.9.0",
64
+ "@molecule/app-ui": "1.5.0",
65
+ "@molecule/app-ui-solid": "1.2.1",
66
66
  "@types/node": "26.6.5",
67
67
  "jsdom": "30.1.3",
68
68
  "solid-js": "1.9.17",