@molecule/app-auth-modal-vue 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 +378 -4
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,11 +1,385 @@
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.790Z
7
+ -->
8
+
1
9
  # @molecule/app-auth-modal-vue
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-vue` — the shared in-app login / signup /
12
+ upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
13
+ providers (where the `@molecule/app-vue` auth composables 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
+ ```ts
27
+ import { createApp, defineComponent, h } from 'vue'
28
+ import { AuthModalMount } from '@molecule/app-auth-modal-vue'
29
+ import { oauthConfig } from './config.js'
30
+
31
+ // Once, inside the app's providers (e.g. in App.ts):
32
+ const App = defineComponent({
33
+ setup() {
34
+ return () => h(AuthModalMount, { oauthConfig, onAuthenticated: () => claimGuestWork() })
35
+ },
36
+ })
37
+ // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
38
+ // anywhere in the app is now intercepted — no other wiring needed.
4
39
 
40
+ createApp(App).mount('#app')
5
41
  ```
6
- npm install @molecule/app-auth-modal-vue
42
+
43
+ ## Type
44
+
45
+ `feature`
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ npm install @molecule/app-auth-modal-vue @molecule/app-auth-shell-vue @molecule/app-i18n @molecule/app-oauth-buttons-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
7
51
  ```
8
52
 
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.
53
+ ## API
54
+
55
+ ### Interfaces
56
+
57
+ #### `AuthModalProps`
58
+
59
+ Props for {@link AuthModal}.
60
+
61
+ ```typescript
62
+ interface AuthModalProps {
63
+ /** Whether the modal is open. */
64
+ open: boolean
65
+ /** Close without authenticating (backdrop / Escape / ✕). */
66
+ onClose?: () => void
67
+ /** Which form to open on. Defaults to `'signup'`. */
68
+ initialMode?: AuthModalMode
69
+ /**
70
+ * OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
71
+ * from the app's `config.ts`. Drives the popup OAuth buttons.
72
+ */
73
+ oauthConfig: UseOAuthConfig
74
+ /**
75
+ * Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the guest
76
+ * id so the new session can claim its work. Optional.
77
+ */
78
+ onBeforeAuth?: () => void
79
+ /**
80
+ * Run AFTER a successful login/signup/OAuth (the session is already refreshed),
81
+ * still on the same page — e.g. claim guest projects, invalidate usage. Optional.
82
+ */
83
+ onAuthenticated?: () => void | Promise<void>
84
+ /**
85
+ * A human-verification challenge rendered inside the SIGNUP form, above the
86
+ * submit button (e.g. the app's Turnstile/hCaptcha widget). Login is not
87
+ * gated, so the slot is unmounted in login mode — which lets the widget clear
88
+ * its own token when the user switches tabs and re-issue a fresh one on the
89
+ * way back. Passed as a prop or as the same-named slot.
90
+ *
91
+ * The modal stays provider-agnostic: it renders the node and never inspects
92
+ * it. An app whose signup API requires a challenge MUST pass
93
+ * {@link AuthModalProps.captchaSolved} as well, or the form will submit
94
+ * without a token and the API will reject it.
95
+ *
96
+ * Optional — omitted (the default for apps with no challenge) the signup form
97
+ * is unchanged.
98
+ */
99
+ captchaSlot?: VNodeChild | null
100
+ /**
101
+ * Whether the {@link AuthModalProps.captchaSlot} challenge is currently
102
+ * solved. `false` disables the signup submit, so the form cannot POST a
103
+ * missing/expired token. Defaults to `true` (no challenge → nothing to wait
104
+ * for). Ignored in login mode.
105
+ */
106
+ captchaSolved?: boolean
107
+ }
108
+ ```
109
+
110
+ #### `AuthModalMountProps`
111
+
112
+ Props for {@link AuthModalMount}.
113
+
114
+ ```typescript
115
+ interface AuthModalMountProps {
116
+ /** OAuth config from the app's `config.ts` (drives the popup OAuth buttons). */
117
+ oauthConfig: AuthModalProps['oauthConfig']
118
+ /** Run before any login attempt (e.g. stash the guest id). Optional. */
119
+ onBeforeAuth?: () => void
120
+ /** Run after a successful login (session already refreshed). Optional. */
121
+ onAuthenticated?: () => void | Promise<void>
122
+ /**
123
+ * Run when the user returns to this tab after the upgrade tab (the session is
124
+ * already refreshed here) — e.g. invalidate usage so a budget banner clears.
125
+ * Only fires for the default new-tab flow; irrelevant when
126
+ * {@link AuthModalMountProps.onUpgradeIntercept} is set. Optional.
127
+ */
128
+ onUpgradeReturn?: () => void
129
+ /**
130
+ * Take over upgrade/billing CTA clicks instead of opening a new tab: called
131
+ * with the matched upgrade path (e.g. `/pricing`), navigation already
132
+ * prevented. The host renders its own upgrade UI (typically a modal) and owns
133
+ * refreshing the session when that flow completes. Optional — when omitted,
134
+ * the default new-tab flow (+ focus-return refresh) applies.
135
+ */
136
+ onUpgradeIntercept?: (path: string) => void
137
+ /**
138
+ * Human-verification challenge rendered inside the modal's SIGNUP form — see
139
+ * {@link AuthModalProps.captchaSlot}. Pass it together with
140
+ * {@link AuthModalMountProps.captchaSolved} whenever the app's signup API
141
+ * requires a challenge token, otherwise the in-app signup POSTs without one
142
+ * while the standalone `/signup` page (which renders its own widget) works —
143
+ * a mismatch the user experiences as "complete the challenge" with no
144
+ * challenge on screen. Optional.
145
+ */
146
+ captchaSlot?: AuthModalProps['captchaSlot']
147
+ /** Whether {@link AuthModalMountProps.captchaSlot} is solved; `false` disables the signup submit. Defaults to `true`. */
148
+ captchaSolved?: boolean
149
+ /** Override the auth path→mode map (defaults to `/login`,`/signup`). */
150
+ authPaths?: Readonly<Record<string, AuthModalMode>>
151
+ /** Override the upgrade paths opened in a new tab (defaults to `/pricing`,`/billing`). */
152
+ upgradePaths?: readonly string[]
153
+ }
154
+ ```
155
+
156
+ ### Types
157
+
158
+ #### `AuthModalMode`
159
+
160
+ Which form {@link AuthModal} should show.
161
+
162
+ ```typescript
163
+ type AuthModalMode = 'login' | 'signup'
164
+ ```
165
+
166
+ ### Functions
167
+
168
+ #### `authModeForHref(href, origin, authPaths)`
169
+
170
+ Map a CTA link's href to the auth mode it should open, or `null` if it is not
171
+ an auth link (so the interceptor leaves it alone).
172
+
173
+ ```typescript
174
+ function authModeForHref(
175
+ href: string | null | undefined,
176
+ origin: string,
177
+ authPaths?: Readonly<Record<string, AuthModalMode>>,
178
+ ): AuthModalMode | null
179
+ ```
180
+
181
+ - `href` — The clicked anchor's href (relative or absolute).
182
+ - `origin` — The page origin to resolve a relative href against.
183
+ - `authPaths` — Path→mode map (defaults to {@link DEFAULT_AUTH_PATHS}).
184
+
185
+ **Returns:** `'login'` / `'signup'`, else `null`.
186
+
187
+ #### `upgradePathForHref(href, origin, upgradePaths)`
188
+
189
+ Whether a CTA link's href points at the upgrade/billing flow (which the
190
+ interceptor hands to the host's `onUpgradeIntercept`, else opens in a new tab).
191
+
192
+ ```typescript
193
+ function upgradePathForHref(
194
+ href: string | null | undefined,
195
+ origin: string,
196
+ upgradePaths?: readonly string[],
197
+ ): string | null
198
+ ```
199
+
200
+ - `href` — The clicked anchor's href (relative or absolute).
201
+ - `origin` — The page origin to resolve a relative href against.
202
+ - `upgradePaths` — The upgrade paths (defaults to {@link DEFAULT_UPGRADE_PATHS}).
203
+
204
+ **Returns:** The matched pathname, else `null`.
205
+
206
+ ### Constants
207
+
208
+ #### `AuthModal`
209
+
210
+ 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.
211
+
212
+ ```typescript
213
+ const AuthModal: DefineComponent<
214
+ ExtractPropTypes<{
215
+ open: { type: BooleanConstructor; default: boolean }
216
+ onClose: PropType<() => void>
217
+ initialMode: { type: PropType<AuthModalMode>; default: string }
218
+ oauthConfig: null
219
+ onBeforeAuth: PropType<() => void>
220
+ onAuthenticated: PropType<() => void | Promise<void>>
221
+ captchaSlot: null
222
+ captchaSolved: { type: BooleanConstructor; default: boolean }
223
+ }>,
224
+ () => VNode,
225
+ {},
226
+ {},
227
+ {},
228
+ ComponentOptionsMixin,
229
+ ComponentOptionsMixin,
230
+ {},
231
+ string,
232
+ PublicProps,
233
+ Readonly<
234
+ ExtractPropTypes<{
235
+ open: { type: BooleanConstructor; default: boolean }
236
+ onClose: PropType<() => void>
237
+ initialMode: { type: PropType<AuthModalMode>; default: string }
238
+ oauthConfig: null
239
+ onBeforeAuth: PropType<() => void>
240
+ onAuthenticated: PropType<() => void | Promise<void>>
241
+ captchaSlot: null
242
+ captchaSolved: { type: BooleanConstructor; default: boolean }
243
+ }>
244
+ > &
245
+ Readonly<{}>,
246
+ { open: boolean; initialMode: AuthModalMode; captchaSolved: boolean },
247
+ {},
248
+ {},
249
+ {},
250
+ string,
251
+ ComponentProvideOptions,
252
+ true,
253
+ {},
254
+ any
255
+ >
256
+ ```
257
+
258
+ - `props` — {@link AuthModalProps}.
259
+
260
+ **Returns:** The modal component (renders nothing when closed).
261
+
262
+ #### `AuthModalMount`
263
+
264
+ 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.
265
+
266
+ ```typescript
267
+ const AuthModalMount: DefineComponent<
268
+ ExtractPropTypes<{
269
+ oauthConfig: null
270
+ onBeforeAuth: PropType<() => void>
271
+ onAuthenticated: PropType<() => void | Promise<void>>
272
+ onUpgradeReturn: PropType<() => void>
273
+ onUpgradeIntercept: PropType<(path: string) => void>
274
+ captchaSlot: null
275
+ captchaSolved: { type: BooleanConstructor; default: boolean }
276
+ authPaths: { type: PropType<Readonly<Record<string, AuthModalMode>>>; default: undefined }
277
+ upgradePaths: { type: PropType<readonly string[]>; default: undefined }
278
+ }>,
279
+ () => VNode | null,
280
+ {},
281
+ {},
282
+ {},
283
+ ComponentOptionsMixin,
284
+ ComponentOptionsMixin,
285
+ {},
286
+ string,
287
+ PublicProps,
288
+ Readonly<
289
+ ExtractPropTypes<{
290
+ oauthConfig: null
291
+ onBeforeAuth: PropType<() => void>
292
+ onAuthenticated: PropType<() => void | Promise<void>>
293
+ onUpgradeReturn: PropType<() => void>
294
+ onUpgradeIntercept: PropType<(path: string) => void>
295
+ captchaSlot: null
296
+ captchaSolved: { type: BooleanConstructor; default: boolean }
297
+ authPaths: { type: PropType<Readonly<Record<string, AuthModalMode>>>; default: undefined }
298
+ upgradePaths: { type: PropType<readonly string[]>; default: undefined }
299
+ }>
300
+ > &
301
+ Readonly<{}>,
302
+ {
303
+ captchaSolved: boolean
304
+ authPaths: Readonly<Record<string, AuthModalMode>>
305
+ upgradePaths: readonly string[]
306
+ },
307
+ {},
308
+ {},
309
+ {},
310
+ string,
311
+ ComponentProvideOptions,
312
+ true,
313
+ {},
314
+ any
315
+ >
316
+ ```
317
+
318
+ - `props` — {@link AuthModalMountProps}.
319
+
320
+ **Returns:** The (lazily-mounted) auth modal component.
321
+
322
+ #### `DEFAULT_AUTH_PATHS`
323
+
324
+ The default in-app auth routes that open the modal.
325
+
326
+ ```typescript
327
+ const DEFAULT_AUTH_PATHS: Readonly<Record<string, AuthModalMode>>
328
+ ```
329
+
330
+ #### `DEFAULT_UPGRADE_PATHS`
331
+
332
+ The default routes that open the upgrade/billing flow (modal or new tab).
333
+
334
+ ```typescript
335
+ const DEFAULT_UPGRADE_PATHS: readonly string[]
336
+ ```
337
+
338
+ ## Injection Notes
339
+
340
+ ### Requirements
341
+
342
+ Peer dependencies:
343
+
344
+ - `@molecule/app-auth-shell-vue` ^1.0.0
345
+ - `@molecule/app-i18n` ^1.0.1
346
+ - `@molecule/app-oauth-buttons-vue` ^1.0.0
347
+ - `@molecule/app-ui` ^1.0.1
348
+ - `@molecule/app-ui-vue` ^1.1.0
349
+ - `@molecule/app-vue` ^3.6.0
350
+ - `vue` ^3.4.0
351
+
352
+ ### Runtime Dependencies
353
+
354
+ - `@molecule/app-auth-shell-vue`
355
+ - `@molecule/app-i18n`
356
+ - `@molecule/app-oauth-buttons-vue`
357
+ - `@molecule/app-ui`
358
+ - `@molecule/app-ui-vue`
359
+ - `@molecule/app-vue`
360
+ - `vue`
361
+
362
+ Interception is capture-phase on `document` and matches plain
363
+ left-clicks on `<a href>` whose resolved pathname is in `authPaths`
364
+ (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
365
+ `/billing`) — modifier/middle clicks still navigate normally, and
366
+ non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
367
+ that render pricing in-place pass `onUpgradeIntercept` and own that UI
368
+
369
+ - the post-upgrade session refresh. `AuthModalMount` must render inside
370
+ the app's auth/HTTP providers (it calls `useAuth`), and the standalone
371
+ `/login` & `/signup` pages should stay routed — they are the fallback
372
+ for modifier clicks and deep links. App-specific extras (stash a guest
373
+ id, claim guest work, invalidate usage) go in `onBeforeAuth` /
374
+ `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
375
+ `@molecule/app-locales-common` bond (79 languages), alongside the
376
+ `auth.login.*` / `auth.signup.*` keys the modal also renders.
10
377
 
11
- License: Apache-2.0
378
+ If the signup API requires a human-verification challenge (Turnstile /
379
+ hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
380
+ form — as a prop or a same-named slot) and `captchaSolved` (which gates
381
+ the submit). Rendering the widget on the standalone `/signup` page alone
382
+ is NOT enough: this modal is what a `/signup` link actually opens, so the
383
+ in-app signup would POST with no token and the API would answer "complete
384
+ the verification challenge" while no challenge is on screen. Login is not
385
+ gated, so the slot is unmounted in login mode.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-auth-modal-vue",
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-vue",
6
6
  "type": "module",
@@ -55,14 +55,14 @@
55
55
  "vue": "^3.4.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@molecule/app-auth-shell-vue": "1.0.0",
58
+ "@molecule/app-auth-shell-vue": "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-vue": "1.2.0",
63
- "@molecule/app-ui": "1.4.0",
64
- "@molecule/app-ui-vue": "1.1.5",
65
- "@molecule/app-vue": "3.7.2",
63
+ "@molecule/app-ui": "1.5.0",
64
+ "@molecule/app-ui-vue": "1.2.1",
65
+ "@molecule/app-vue": "3.9.0",
66
66
  "@types/node": "26.6.5",
67
67
  "jsdom": "30.1.3",
68
68
  "typescript": "6.0.3",