@molecule/app-auth-modal-react 1.0.0 → 1.0.1

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 +260 -0
  2. package/package.json +20 -14
package/README.md ADDED
@@ -0,0 +1,260 @@
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-08-04T01:50:06.179Z
7
+ -->
8
+
9
+ # @molecule/app-auth-modal-react
10
+
11
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
+ > It is written to be read by coding agents as much as by people, and is generated from this
13
+ > package's source — edit `src/index.ts` JSDoc, not this file.
14
+
15
+ `@molecule/app-auth-modal-react` — the shared in-app login / signup /
16
+ upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
17
+ providers (where the `@molecule/app-react` auth hooks work) and every
18
+ in-app `/login` / `/signup` link opens the {@link AuthModal} instead of
19
+ navigating, while `/pricing` / `/billing` links open the upgrade flow in
20
+ a new tab (session auto-refreshes when the user returns) — no
21
+ navigation, no reload, no lost work. OAuth runs in a popup
22
+ (`loginViaPopup`), so social login never navigates the host either.
23
+
24
+ ## Quick Start
25
+
26
+ ```tsx
27
+ import { AuthModalMount } from '@molecule/app-auth-modal-react'
28
+ import { oauthConfig } from './config.js'
29
+
30
+ // Once, inside the app's providers (e.g. in App.tsx):
31
+ ;<AuthModalMount oauthConfig={oauthConfig} onAuthenticated={() => claimGuestWork()} />
32
+ // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
33
+ // anywhere in the app is now intercepted — no other wiring needed.
34
+ ```
35
+
36
+ ## Type
37
+
38
+ `feature`
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @molecule/app-auth-modal-react @molecule/app-auth-shell-react @molecule/app-i18n @molecule/app-oauth-buttons-react @molecule/app-react @molecule/app-ui @molecule/app-ui-react react
44
+ npm install -D @types/react
45
+ ```
46
+
47
+ ## API
48
+
49
+ ### Interfaces
50
+
51
+ #### `AuthModalMountProps`
52
+
53
+ Props for {@link AuthModalMount}.
54
+
55
+ ```typescript
56
+ interface AuthModalMountProps {
57
+ /** OAuth config from the app's `config.ts` (drives the popup OAuth buttons). */
58
+ oauthConfig: AuthModalProps['oauthConfig']
59
+ /** Run before any login attempt (e.g. stash the guest id). Optional. */
60
+ onBeforeAuth?: () => void
61
+ /** Run after a successful login (session already refreshed). Optional. */
62
+ onAuthenticated?: () => void | Promise<void>
63
+ /**
64
+ * Run when the user returns to this tab after the upgrade tab (the session is
65
+ * already refreshed here) — e.g. invalidate usage so a budget banner clears.
66
+ * Only fires for the default new-tab flow; irrelevant when
67
+ * {@link AuthModalMountProps.onUpgradeIntercept} is set. Optional.
68
+ */
69
+ onUpgradeReturn?: () => void
70
+ /**
71
+ * Take over upgrade/billing CTA clicks instead of opening a new tab: called
72
+ * with the matched upgrade path (e.g. `/pricing`), navigation already
73
+ * prevented. The host renders its own upgrade UI (typically a modal) and owns
74
+ * refreshing the session when that flow completes. Optional — when omitted,
75
+ * the default new-tab flow (+ focus-return refresh) applies.
76
+ */
77
+ onUpgradeIntercept?: (path: string) => void
78
+ /** Override the auth path→mode map (defaults to `/login`,`/signup`). */
79
+ authPaths?: Readonly<Record<string, AuthModalMode>>
80
+ /** Override the upgrade paths opened in a new tab (defaults to `/pricing`,`/billing`). */
81
+ upgradePaths?: readonly string[]
82
+ }
83
+ ```
84
+
85
+ #### `AuthModalProps`
86
+
87
+ Props for {@link AuthModal}.
88
+
89
+ ```typescript
90
+ interface AuthModalProps {
91
+ /** Whether the modal is open. */
92
+ open: boolean
93
+ /** Close without authenticating (backdrop / Escape / ✕). */
94
+ onClose: () => void
95
+ /** Which form to open on. Defaults to `'signup'`. */
96
+ initialMode?: AuthModalMode
97
+ /**
98
+ * OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
99
+ * from the app's `config.ts`. Drives the popup OAuth buttons.
100
+ */
101
+ oauthConfig: Parameters<typeof useOAuth>[0]
102
+ /**
103
+ * Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the guest
104
+ * id so the new session can claim its work. Optional.
105
+ */
106
+ onBeforeAuth?: () => void
107
+ /**
108
+ * Run AFTER a successful login/signup/OAuth (the session is already refreshed),
109
+ * still on the same page — e.g. claim guest projects, invalidate usage. Optional.
110
+ */
111
+ onAuthenticated?: () => void | Promise<void>
112
+ }
113
+ ```
114
+
115
+ ### Types
116
+
117
+ #### `AuthModalMode`
118
+
119
+ Which form {@link AuthModal} should show.
120
+
121
+ ```typescript
122
+ type AuthModalMode = 'login' | 'signup'
123
+ ```
124
+
125
+ ### Functions
126
+
127
+ #### `AuthModal(props)`
128
+
129
+ 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.
130
+
131
+ ```typescript
132
+ function AuthModal({
133
+ open,
134
+ onClose,
135
+ initialMode = 'signup',
136
+ oauthConfig,
137
+ onBeforeAuth,
138
+ onAuthenticated,
139
+ }: AuthModalProps): JSX.Element
140
+ ```
141
+
142
+ - `props` — {@link AuthModalProps}.
143
+
144
+ **Returns:** The modal element (renders nothing when closed).
145
+
146
+ #### `AuthModalMount(props)`
147
+
148
+ 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.
149
+
150
+ ```typescript
151
+ function AuthModalMount({
152
+ oauthConfig,
153
+ onBeforeAuth,
154
+ onAuthenticated,
155
+ onUpgradeReturn,
156
+ onUpgradeIntercept,
157
+ authPaths = DEFAULT_AUTH_PATHS,
158
+ upgradePaths = DEFAULT_UPGRADE_PATHS,
159
+ }: AuthModalMountProps): JSX.Element
160
+ ```
161
+
162
+ - `props` — {@link AuthModalMountProps}.
163
+
164
+ **Returns:** The (lazily-mounted) auth modal element.
165
+
166
+ #### `authModeForHref(href, origin, authPaths)`
167
+
168
+ Map a CTA link's href to the auth mode it should open, or `null` if it is not
169
+ an auth link (so the interceptor leaves it alone).
170
+
171
+ ```typescript
172
+ function authModeForHref(
173
+ href: string | null | undefined,
174
+ origin: string,
175
+ authPaths?: Readonly<Record<string, AuthModalMode>>,
176
+ ): AuthModalMode | null
177
+ ```
178
+
179
+ - `href` — The clicked anchor's href (relative or absolute).
180
+ - `origin` — The page origin to resolve a relative href against.
181
+ - `authPaths` — Path→mode map (defaults to {@link DEFAULT_AUTH_PATHS}).
182
+
183
+ **Returns:** `'login'` / `'signup'`, else `null`.
184
+
185
+ #### `upgradePathForHref(href, origin, upgradePaths)`
186
+
187
+ Whether a CTA link's href points at the upgrade/billing flow (which the
188
+ interceptor hands to the host's `onUpgradeIntercept`, else opens in a new tab).
189
+
190
+ ```typescript
191
+ function upgradePathForHref(
192
+ href: string | null | undefined,
193
+ origin: string,
194
+ upgradePaths?: readonly string[],
195
+ ): string | null
196
+ ```
197
+
198
+ - `href` — The clicked anchor's href (relative or absolute).
199
+ - `origin` — The page origin to resolve a relative href against.
200
+ - `upgradePaths` — The upgrade paths (defaults to {@link DEFAULT_UPGRADE_PATHS}).
201
+
202
+ **Returns:** The matched pathname, else `null`.
203
+
204
+ ### Constants
205
+
206
+ #### `DEFAULT_AUTH_PATHS`
207
+
208
+ The default in-app auth routes that open the modal.
209
+
210
+ ```typescript
211
+ const DEFAULT_AUTH_PATHS: Readonly<Record<string, AuthModalMode>>
212
+ ```
213
+
214
+ #### `DEFAULT_UPGRADE_PATHS`
215
+
216
+ The default routes that open the upgrade/billing flow (modal or new tab).
217
+
218
+ ```typescript
219
+ const DEFAULT_UPGRADE_PATHS: readonly string[]
220
+ ```
221
+
222
+ ## Injection Notes
223
+
224
+ ### Requirements
225
+
226
+ Peer dependencies:
227
+
228
+ - `@molecule/app-auth-shell-react` ^1.0.1
229
+ - `@molecule/app-i18n` ^1.0.1
230
+ - `@molecule/app-oauth-buttons-react` ^1.0.1
231
+ - `@molecule/app-react` ^1.0.1
232
+ - `@molecule/app-ui` ^1.0.1
233
+ - `@molecule/app-ui-react` ^1.0.1
234
+ - `react` ^18.0.0 || ^19.0.0
235
+
236
+ ### Runtime Dependencies
237
+
238
+ - `@molecule/app-auth-shell-react`
239
+ - `@molecule/app-i18n`
240
+ - `@molecule/app-oauth-buttons-react`
241
+ - `@molecule/app-react`
242
+ - `@molecule/app-ui`
243
+ - `@molecule/app-ui-react`
244
+ - `react`
245
+
246
+ Interception is capture-phase on `document` and matches plain
247
+ left-clicks on `<a href>` whose resolved pathname is in `authPaths`
248
+ (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
249
+ `/billing`) — modifier/middle clicks still navigate normally, and
250
+ non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
251
+ that render pricing in-place pass `onUpgradeIntercept` and own that UI
252
+
253
+ - the post-upgrade session refresh. `AuthModalMount` must render inside
254
+ the app's auth/HTTP providers (it calls `useAuth`), and the standalone
255
+ `/login` & `/signup` pages should stay routed — they are the fallback
256
+ for modifier clicks and deep links. App-specific extras (stash a guest
257
+ id, claim guest work, invalidate usage) go in `onBeforeAuth` /
258
+ `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
259
+ `@molecule/app-locales-common` bond (79 languages), alongside the
260
+ `auth.login.*` / `auth.signup.*` keys the modal also renders.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-auth-modal-react",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,8 @@
17
17
  }
18
18
  },
19
19
  "files": [
20
- "dist"
20
+ "dist",
21
+ "README.md"
21
22
  ],
22
23
  "keywords": [
23
24
  "molecule",
@@ -29,22 +30,27 @@
29
30
  "react"
30
31
  ],
31
32
  "license": "Apache-2.0",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/molecule-dev/molecule.git",
36
+ "directory": "packages/app/features/auth-modal-react"
37
+ },
32
38
  "peerDependencies": {
33
- "@molecule/app-auth-shell-react": "^1.0.0",
34
- "@molecule/app-i18n": "^1.0.0",
35
- "@molecule/app-oauth-buttons-react": "^1.0.0",
36
- "@molecule/app-react": "^1.0.0",
37
- "@molecule/app-ui": "^1.0.0",
38
- "@molecule/app-ui-react": "^1.0.0",
39
+ "@molecule/app-auth-shell-react": "^1.0.1",
40
+ "@molecule/app-i18n": "^1.0.1",
41
+ "@molecule/app-oauth-buttons-react": "^1.0.1",
42
+ "@molecule/app-react": "^1.0.1",
43
+ "@molecule/app-ui": "^1.0.1",
44
+ "@molecule/app-ui-react": "^1.0.1",
39
45
  "react": "^18.0.0 || ^19.0.0"
40
46
  },
41
47
  "devDependencies": {
42
- "@molecule/app-auth-shell-react": "1.0.0",
43
- "@molecule/app-i18n": "1.0.0",
44
- "@molecule/app-oauth-buttons-react": "1.0.0",
45
- "@molecule/app-react": "1.0.0",
46
- "@molecule/app-ui": "1.0.0",
47
- "@molecule/app-ui-react": "1.0.0",
48
+ "@molecule/app-auth-shell-react": "1.0.1",
49
+ "@molecule/app-i18n": "1.0.1",
50
+ "@molecule/app-oauth-buttons-react": "1.0.1",
51
+ "@molecule/app-react": "1.0.1",
52
+ "@molecule/app-ui": "1.0.1",
53
+ "@molecule/app-ui-react": "1.0.1",
48
54
  "@testing-library/react": "16.3.2",
49
55
  "@types/node": "26.1.2",
50
56
  "@types/react": "19.2.17",