@molecule/app-auth-modal-svelte 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 +269 -4
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,11 +1,276 @@
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.459Z
7
+ -->
8
+
1
9
  # @molecule/app-auth-modal-svelte
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-svelte` — the shared in-app login / signup /
12
+ upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
13
+ providers (where the `@molecule/app-svelte` auth hooks 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
+ ```svelte
27
+ <script lang="ts">
28
+ import { AuthModalMount } from '@molecule/app-auth-modal-svelte'
29
+ import { oauthConfig } from './config.js'
30
+ </script>
31
+
32
+ <!-- Once, inside the app's providers (e.g. in App.svelte): -->
33
+ <AuthModalMount {oauthConfig} onAuthenticated={() => claimGuestWork()} />
34
+ <!-- Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
35
+ anywhere in the app is now intercepted — no other wiring needed. -->
36
+ ```
37
+
38
+ ## Type
39
+
40
+ `feature`
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ npm install @molecule/app-auth-modal-svelte @molecule/app-auth-shell-svelte @molecule/app-i18n @molecule/app-oauth-buttons-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
46
+ ```
47
+
48
+ ## API
49
+
50
+ ### Interfaces
51
+
52
+ #### `AuthModalProps`
53
+
54
+ Props accepted by the {@link AuthModal} component.
55
+
56
+ ```typescript
57
+ interface AuthModalProps {
58
+ /** Whether the modal is open. */
59
+ open: boolean
60
+ /** Close without authenticating (backdrop / Escape / ✕). */
61
+ onClose?: () => void
62
+ /** Which form to open on. Defaults to `'signup'`. */
63
+ initialMode?: AuthModalMode
64
+ /**
65
+ * OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
66
+ * from the app's `config.ts`. Drives the popup OAuth buttons.
67
+ */
68
+ oauthConfig: UseOAuthConfig
69
+ /**
70
+ * Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the
71
+ * guest id so the new session can claim its work. Optional.
72
+ */
73
+ onBeforeAuth?: () => void
74
+ /**
75
+ * Run AFTER a successful login/signup/OAuth (the session is already
76
+ * refreshed), still on the same page — e.g. claim guest projects, invalidate
77
+ * usage. Optional.
78
+ */
79
+ onAuthenticated?: () => void | Promise<void>
80
+ /**
81
+ * A human-verification challenge rendered inside the SIGNUP form, above the
82
+ * submit button (e.g. the app's Turnstile/hCaptcha widget), as a snippet or
83
+ * plain text. Login is not gated, so the slot is unmounted in login mode —
84
+ * which lets the widget clear its own token when the user switches tabs and
85
+ * re-issue a fresh one on the way back.
86
+ *
87
+ * The modal stays provider-agnostic: it renders the node and never inspects
88
+ * it. An app whose signup API requires a challenge MUST pass `captchaSolved`
89
+ * as well, or the form will submit without a token and the API will reject
90
+ * it. Optional — omitted (the default for apps with no challenge) the signup
91
+ * form is unchanged.
92
+ */
93
+ captchaSlot?: ReactNodeProp
94
+ /**
95
+ * Whether the `captchaSlot` challenge is currently solved. `false` disables
96
+ * the signup submit, so the form cannot POST a missing/expired token.
97
+ * Defaults to `true` (no challenge → nothing to wait for). Ignored in login
98
+ * mode.
99
+ */
100
+ captchaSolved?: boolean
101
+ }
102
+ ```
103
+
104
+ #### `AuthModalMountProps`
105
+
106
+ Props accepted by the {@link AuthModalMount} component.
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
118
+ * is already refreshed here) — e.g. invalidate usage so a budget banner
119
+ * clears. Only fires for the default new-tab flow; irrelevant when
120
+ * `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
127
+ * owns refreshing the session when that flow completes. Optional — when
128
+ * omitted, 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
+ * `AuthModalProps.captchaSlot`. Pass it together with `captchaSolved`
134
+ * whenever the app's signup API requires a challenge token, otherwise the
135
+ * in-app signup POSTs without one while the standalone `/signup` page (which
136
+ * renders its own widget) works — a mismatch the user experiences as
137
+ * "complete the challenge" with no challenge on screen. Optional.
138
+ */
139
+ captchaSlot?: AuthModalProps['captchaSlot']
140
+ /** Whether `captchaSlot` is solved; `false` disables the signup submit. Defaults to `true`. */
141
+ captchaSolved?: boolean
142
+ /** Override the auth path→mode map (defaults to `/login`,`/signup`). */
143
+ authPaths?: Readonly<Record<string, AuthModalMode>>
144
+ /** Override the upgrade paths opened in a new tab (defaults to `/pricing`,`/billing`). */
145
+ upgradePaths?: readonly string[]
146
+ }
147
+ ```
148
+
149
+ ### Types
150
+
151
+ #### `AuthModalMode`
152
+
153
+ Which form {@link AuthModal} should show.
154
+
155
+ ```typescript
156
+ type AuthModalMode = 'login' | 'signup'
157
+ ```
158
+
159
+ ### Functions
160
+
161
+ #### `authModeForHref(href, origin, authPaths)`
162
+
163
+ Map a CTA link's href to the auth mode it should open, or `null` if it is not
164
+ an auth link (so the interceptor leaves it alone).
4
165
 
166
+ ```typescript
167
+ function authModeForHref(
168
+ href: string | null | undefined,
169
+ origin: string,
170
+ authPaths?: Readonly<Record<string, AuthModalMode>>,
171
+ ): AuthModalMode | null
5
172
  ```
6
- npm install @molecule/app-auth-modal-svelte
173
+
174
+ - `href` — The clicked anchor's href (relative or absolute).
175
+ - `origin` — The page origin to resolve a relative href against.
176
+ - `authPaths` — Path→mode map (defaults to {@link DEFAULT_AUTH_PATHS}).
177
+
178
+ **Returns:** `'login'` / `'signup'`, else `null`.
179
+
180
+ #### `upgradePathForHref(href, origin, upgradePaths)`
181
+
182
+ Whether a CTA link's href points at the upgrade/billing flow (which the
183
+ interceptor hands to the host's `onUpgradeIntercept`, else opens in a new tab).
184
+
185
+ ```typescript
186
+ function upgradePathForHref(
187
+ href: string | null | undefined,
188
+ origin: string,
189
+ upgradePaths?: readonly string[],
190
+ ): string | null
7
191
  ```
8
192
 
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.
193
+ - `href` — The clicked anchor's href (relative or absolute).
194
+ - `origin` — The page origin to resolve a relative href against.
195
+ - `upgradePaths` — The upgrade paths (defaults to {@link DEFAULT_UPGRADE_PATHS}).
196
+
197
+ **Returns:** The matched pathname, else `null`.
198
+
199
+ ### Constants
200
+
201
+ #### `AuthModal`
202
+
203
+ ```typescript
204
+ const AuthModal: LegacyComponentType
205
+ ```
206
+
207
+ #### `AuthModalMount`
208
+
209
+ ```typescript
210
+ const AuthModalMount: LegacyComponentType
211
+ ```
212
+
213
+ #### `DEFAULT_AUTH_PATHS`
214
+
215
+ The default in-app auth routes that open the modal.
216
+
217
+ ```typescript
218
+ const DEFAULT_AUTH_PATHS: Readonly<Record<string, AuthModalMode>>
219
+ ```
220
+
221
+ #### `DEFAULT_UPGRADE_PATHS`
222
+
223
+ The default routes that open the upgrade/billing flow (modal or new tab).
224
+
225
+ ```typescript
226
+ const DEFAULT_UPGRADE_PATHS: readonly string[]
227
+ ```
228
+
229
+ ## Injection Notes
230
+
231
+ ### Requirements
232
+
233
+ Peer dependencies:
234
+
235
+ - `@molecule/app-auth-shell-svelte` ^1.0.0
236
+ - `@molecule/app-i18n` ^1.0.1
237
+ - `@molecule/app-oauth-buttons-svelte` ^1.0.0
238
+ - `@molecule/app-svelte` ^3.5.0
239
+ - `@molecule/app-ui` ^1.0.1
240
+ - `@molecule/app-ui-svelte` ^1.1.0
241
+ - `svelte` ^5.0.0
242
+
243
+ ### Runtime Dependencies
244
+
245
+ - `@molecule/app-auth-shell-svelte`
246
+ - `@molecule/app-i18n`
247
+ - `@molecule/app-oauth-buttons-svelte`
248
+ - `@molecule/app-svelte`
249
+ - `@molecule/app-ui`
250
+ - `@molecule/app-ui-svelte`
251
+ - `svelte`
252
+
253
+ Interception is capture-phase on `document` and matches plain
254
+ left-clicks on `<a href>` whose resolved pathname is in `authPaths`
255
+ (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
256
+ `/billing`) — modifier/middle clicks still navigate normally, and
257
+ non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
258
+ that render pricing in-place pass `onUpgradeIntercept` and own that UI
259
+
260
+ - the post-upgrade session refresh. `AuthModalMount` must render inside
261
+ the app's auth/HTTP providers (it calls `useAuth`), and the standalone
262
+ `/login` & `/signup` pages should stay routed — they are the fallback
263
+ for modifier clicks and deep links. App-specific extras (stash a guest
264
+ id, claim guest work, invalidate usage) go in `onBeforeAuth` /
265
+ `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
266
+ `@molecule/app-locales-common` bond (79 languages), alongside the
267
+ `auth.login.*` / `auth.signup.*` keys the modal also renders.
10
268
 
11
- License: Apache-2.0
269
+ If the signup API requires a human-verification challenge (Turnstile /
270
+ hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
271
+ form, as a snippet or plain text) and `captchaSolved` (which gates the
272
+ submit). Rendering the widget on the standalone `/signup` page alone is
273
+ NOT enough: this modal is what a `/signup` link actually opens, so the
274
+ in-app signup would POST with no token and the API would answer "complete
275
+ the verification challenge" while no challenge is on screen. Login is not
276
+ 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-svelte",
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-svelte",
6
6
  "type": "module",
@@ -61,14 +61,14 @@
61
61
  "svelte": "^5.0.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@molecule/app-auth-shell-svelte": "1.0.0",
64
+ "@molecule/app-auth-shell-svelte": "1.1.0",
65
65
  "@molecule/app-framework-conformance": "0.0.0",
66
66
  "@molecule/app-i18n": "1.2.2",
67
67
  "@molecule/app-icons": "1.0.4",
68
68
  "@molecule/app-oauth-buttons-svelte": "1.2.0",
69
- "@molecule/app-svelte": "3.7.2",
70
- "@molecule/app-ui": "1.4.0",
71
- "@molecule/app-ui-svelte": "1.1.7",
69
+ "@molecule/app-svelte": "3.9.0",
70
+ "@molecule/app-ui": "1.5.0",
71
+ "@molecule/app-ui-svelte": "1.2.1",
72
72
  "@sveltejs/package": "3.0.2",
73
73
  "@sveltejs/vite-plugin-svelte": "7.1.2",
74
74
  "@types/node": "26.6.5",