@molecule/app-auth-modal-solid 0.0.0-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.
@@ -0,0 +1,310 @@
1
+ /**
2
+ * In-app login / signup modal — authenticate WITHOUT leaving the page.
3
+ *
4
+ * Solid counterpart of `@molecule/app-auth-modal-react`'s `AuthModal`: the
5
+ * same props (React names), the same ClassMap tokens, the same i18n keys, and
6
+ * the same DOM for the same input.
7
+ *
8
+ * Reuses the Solid auth primitives (`useLogin` / `useSignup` / `useOAuth` /
9
+ * `useAuth`) so behavior matches the standalone `/login` and `/signup` pages,
10
+ * but on success it stays in place: it refreshes the session (so guards + plan
11
+ * are current), runs an optional app `onAuthenticated` hook (e.g. claim guest
12
+ * work, invalidate usage), and closes — no navigation, no reload. OAuth runs
13
+ * in a POPUP (`loginViaPopup`) so social login never navigates the host
14
+ * either.
15
+ *
16
+ * @module
17
+ */
18
+ import { createEffect, createRenderEffect, createSignal, on, onCleanup, onMount, Show, } from 'solid-js';
19
+ import { useAuthFormState } from '@molecule/app-auth-shell-solid';
20
+ import { OAuthButtons, OAuthDivider } from '@molecule/app-oauth-buttons-solid';
21
+ import { useAuth, useAuthClient, useI18nError, useLogin, useOAuth, useSignup, useTranslation, } from '@molecule/app-solid';
22
+ import { getClassMap } from '@molecule/app-ui';
23
+ import { Button, Icon, Modal } from '@molecule/app-ui-solid';
24
+ /**
25
+ * Matches phones (narrow viewport) OR touch-first devices (coarse primary
26
+ * pointer) — the contexts where a sub-16px input font makes iOS Safari zoom
27
+ * the whole page on focus.
28
+ */
29
+ const TOUCH_FIRST_QUERY = '(max-width: 767px), (pointer: coarse)';
30
+ /**
31
+ * How long the "Signed up!" / "Logged in!" confirmation stays visible before
32
+ * the modal closes. Long enough to register, short enough not to feel like a
33
+ * wait — and the app's `onAuthenticated` work (claiming guest projects etc.)
34
+ * runs concurrently, so the real delay is `max(this, onAuthenticated)`.
35
+ */
36
+ const SUCCESS_DISPLAY_MS = 1000;
37
+ /**
38
+ * Whether {@link TOUCH_FIRST_QUERY} currently matches. SSR-safe (reports
39
+ * `false` until mounted in a browser) and subscribes to media-query changes
40
+ * (rotation, window resize across the breakpoint). Local to this package — it
41
+ * must not import IDE feature packages for a two-line media-query check.
42
+ * @returns True on phone-width or touch-first devices.
43
+ */
44
+ function useTouchFirstViewport() {
45
+ const [matches, setMatches] = createSignal(typeof window !== 'undefined' &&
46
+ typeof window.matchMedia === 'function' &&
47
+ window.matchMedia(TOUCH_FIRST_QUERY).matches);
48
+ onMount(() => {
49
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function')
50
+ return;
51
+ const mql = window.matchMedia(TOUCH_FIRST_QUERY);
52
+ const onChange = (e) => {
53
+ setMatches(e.matches);
54
+ };
55
+ setMatches(mql.matches);
56
+ mql.addEventListener('change', onChange);
57
+ onCleanup(() => {
58
+ mql.removeEventListener('change', onChange);
59
+ });
60
+ });
61
+ return matches;
62
+ }
63
+ /**
64
+ * 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.
65
+ *
66
+ * @param props - {@link AuthModalProps}.
67
+ * @returns The modal element (renders nothing when closed).
68
+ */
69
+ export const AuthModal = (props) => {
70
+ const { t } = useTranslation();
71
+ const cm = getClassMap();
72
+ const isTouchFirst = useTouchFirstViewport();
73
+ // React's `useState(initialMode)`: read once, then owned by the component.
74
+ const [mode, setMode] = createSignal(props.initialMode ?? 'signup');
75
+ const { refresh } = useAuth();
76
+ const authClient = useAuthClient();
77
+ const { status: loginStatus, error: loginError, login } = useLogin();
78
+ const { status: signupStatus, error: signupError, signup } = useSignup();
79
+ const { fields, setField, clear } = useAuthFormState();
80
+ const [password, setPassword] = createSignal('');
81
+ const [name, setName] = createSignal('');
82
+ const [twoFactorToken, setTwoFactorToken] = createSignal('');
83
+ const [oauthError, setOauthError] = createSignal(null);
84
+ // Post-auth confirmation ("Signed up!" / "Logged in!") shown briefly before
85
+ // the modal closes — without it the modal just vanished, which read as
86
+ // "nothing happened".
87
+ const [succeeded, setSucceeded] = createSignal(false);
88
+ const isSignup = () => mode() === 'signup';
89
+ const busy = () => (isSignup() ? signupStatus() : loginStatus()) === 'pending';
90
+ const errorMessage = useI18nError(() => (isSignup() ? signupError() : loginError()));
91
+ // Dialog pattern (WAI-ARIA): when the modal opens, keyboard and
92
+ // screen-reader users land on the form's primary field instead of on the
93
+ // page behind the overlay. This replaces the `autoFocus` prop, which
94
+ // jsx-a11y/no-autofocus bars: the prop fires on EVERY mount of the input
95
+ // (e.g. the brief remount after the mode switches), while this effect runs
96
+ // exactly once per open transition. Solid creates the parent's effects
97
+ // before the Modal child's own focus-trap effect and both defer one
98
+ // microtask, so this defers two — the email field then wins in both signup
99
+ // and login mode (React's child-effects-first ordering).
100
+ let emailRef;
101
+ const focusEmail = () => {
102
+ if (props.open)
103
+ emailRef?.focus();
104
+ };
105
+ createEffect(on(() => props.open, (open) => {
106
+ if (open)
107
+ queueMicrotask(() => queueMicrotask(focusEmail));
108
+ }, { defer: true }));
109
+ onMount(() => {
110
+ if (props.open)
111
+ queueMicrotask(() => queueMicrotask(focusEmail));
112
+ });
113
+ // Universal post-auth: refresh the session (guards + plan current), show a
114
+ // brief confirmation, run the app's hook, then close — all in place, no
115
+ // navigation.
116
+ const finishAuth = async () => {
117
+ try {
118
+ await refresh();
119
+ }
120
+ catch (error) {
121
+ // Every path into finishAuth (password login/signup response, OAuth popup
122
+ // relay) has already established the session client-side, so the refresh
123
+ // is a freshness pass — a failure here (e.g. an API with neither a
124
+ // refresh endpoint nor cookie restore) must NOT strand an authenticated
125
+ // user in the modal with their account already created. Only a genuinely
126
+ // absent session is a real failure.
127
+ if (!authClient.isAuthenticated())
128
+ throw error;
129
+ }
130
+ setSucceeded(true);
131
+ // Hold the confirmation on screen while the app hook runs; whichever
132
+ // finishes last gates the close.
133
+ const minDisplay = new Promise((resolve) => setTimeout(resolve, SUCCESS_DISPLAY_MS));
134
+ await props.onAuthenticated?.();
135
+ await minDisplay;
136
+ props.onClose?.();
137
+ };
138
+ // OAuth (popup): success/error land back on THIS page; wire them into the
139
+ // primitive. An accessor keeps the closures current (React re-creates the
140
+ // config object every render).
141
+ const oauth = useOAuth(() => ({
142
+ ...props.oauthConfig,
143
+ onSuccess: () => {
144
+ // Surface a finishAuth failure (no session established) in the modal
145
+ // instead of dying as an unhandled rejection.
146
+ finishAuth().catch((error) => {
147
+ setOauthError(error instanceof Error ? error.message : String(error));
148
+ });
149
+ },
150
+ onError: (message) => {
151
+ setOauthError(message);
152
+ },
153
+ }));
154
+ const handleSubmit = async (e) => {
155
+ e.preventDefault();
156
+ props.onBeforeAuth?.();
157
+ try {
158
+ if (isSignup())
159
+ await signup({
160
+ email: fields().email ?? '',
161
+ password: password(),
162
+ name: name() || undefined,
163
+ });
164
+ else
165
+ await login({ email: fields().email ?? '', password: password() });
166
+ clear();
167
+ await finishAuth();
168
+ }
169
+ catch (_error) {
170
+ // Auth errors are captured in the primitive's error state and shown
171
+ // below; we deliberately do NOT navigate or reload on failure or success.
172
+ }
173
+ };
174
+ /** The shared input inline style, sized for the current viewport class. */
175
+ const fieldStyle = () => ({
176
+ width: '100%',
177
+ padding: '10px 12px',
178
+ 'border-radius': '6px',
179
+ border: '1px solid var(--mol-color-border, rgba(127,127,127,0.3))',
180
+ background: 'var(--mol-color-surface-secondary, rgba(127,127,127,0.06))',
181
+ color: 'inherit',
182
+ outline: 'none',
183
+ // ≥16px on phones/touch — below 16px iOS Safari zooms the page when an
184
+ // input gains focus, which wrecks the modal on the primary conversion
185
+ // flow. Desktop keeps the compact 14px.
186
+ 'font-size': isTouchFirst() ? '16px' : '14px',
187
+ });
188
+ /**
189
+ * react-dom writes a controlled value through BOTH the live property and the
190
+ * `value` attribute; Solid's `value` binding writes only the property. The
191
+ * ref callback (same pattern as `@molecule/app-amount-input-solid`) keeps
192
+ * both current for the element's lifetime.
193
+ *
194
+ * @param text - Accessor of the controlled value.
195
+ * @returns The ref callback to attach.
196
+ */
197
+ const syncInput = (text) => (el) => {
198
+ createRenderEffect(() => {
199
+ const next = text();
200
+ if (el.value !== next)
201
+ el.value = next;
202
+ if (el.getAttribute('value') !== next)
203
+ el.setAttribute('value', next);
204
+ });
205
+ };
206
+ return (<Modal open={props.open} onClose={() => props.onClose?.()} size="sm" title={isSignup()
207
+ ? t('auth.modal.signupTitle', undefined, { defaultValue: 'Create your account' })
208
+ : t('auth.modal.loginTitle', undefined, { defaultValue: 'Log in' })} data-mol-id="auth-modal">
209
+ <div data-mol-id="auth-modal-body" style={{ display: 'flex', 'flex-direction': 'column' }}>
210
+ <Show when={succeeded()} fallback={<>
211
+ <div class={cm.textMuted} style={{ 'margin-bottom': '12px', 'font-size': '13px', 'line-height': '1.45' }}>
212
+ {isSignup()
213
+ ? t('auth.modal.signupBlurb', undefined, {
214
+ defaultValue: 'Sign up to keep your work.',
215
+ })
216
+ : t('auth.modal.loginBlurb', undefined, {
217
+ defaultValue: 'Log in to keep your work.',
218
+ })}
219
+ </div>
220
+ <form onSubmit={(e) => void handleSubmit(e)} style={{ display: 'grid', gap: '10px' }}>
221
+ <Show when={isSignup()}>
222
+ <input type="text" ref={syncInput(name)} onInput={(e) => setName(e.currentTarget.value)} autocomplete="name" data-mol-id="auth-modal-name" placeholder={t('auth.signup.name', undefined, {
223
+ defaultValue: 'Name (optional)',
224
+ })} style={fieldStyle()}/>
225
+ </Show>
226
+ <input type="email" onInput={(e) => setField('email', e.currentTarget.value)} autocomplete="email" ref={(el) => {
227
+ emailRef = el;
228
+ syncInput(() => fields().email ?? '')(el);
229
+ }} required data-mol-id="auth-modal-email" placeholder={t('auth.login.email', undefined, { defaultValue: 'Email' })} style={fieldStyle()}/>
230
+ <input type="password" ref={syncInput(password)} onInput={(e) => setPassword(e.currentTarget.value)} autocomplete={isSignup() ? 'new-password' : 'current-password'} required data-mol-id="auth-modal-password" placeholder={t('auth.login.password', undefined, { defaultValue: 'Password' })} style={fieldStyle()}/>
231
+ <Show when={!isSignup()}>
232
+ <input type="text" inputmode="numeric" ref={syncInput(twoFactorToken)} onInput={(e) => setTwoFactorToken(e.currentTarget.value)} autocomplete="one-time-code" data-mol-id="auth-modal-2fa" placeholder={t('auth.login.twoFactor', undefined, {
233
+ defaultValue: 'Two-Factor Token (If enabled)',
234
+ })} style={fieldStyle()}/>
235
+ </Show>
236
+ {/* Human-verification challenge — signup only (login is not gated). */}
237
+ <Show when={isSignup() && props.captchaSlot}>
238
+ <div data-mol-id="auth-modal-captcha" style={{ display: 'grid', 'margin-top': '2px' }}>
239
+ {props.captchaSlot}
240
+ </div>
241
+ </Show>
242
+ <Button type="submit" size="lg" color="success" disabled={busy() || (isSignup() && !(props.captchaSolved ?? true))} data-mol-id="auth-modal-submit" style={{ width: '100%', 'margin-top': '2px' }}>
243
+ {busy()
244
+ ? t('auth.modal.working', undefined, { defaultValue: 'Just a moment…' })
245
+ : isSignup()
246
+ ? t('auth.login.signUp', undefined, { defaultValue: 'Sign up' })
247
+ : t('auth.login.logIn', undefined, { defaultValue: 'Log in' })}
248
+ </Button>
249
+ {(errorMessage() || oauthError()) && (<div class={cm.authFormError}>{errorMessage() || oauthError()}</div>)}
250
+ </form>
251
+ <Show when={oauth.providers.length > 0}>
252
+ <div style={{ 'margin-top': '4px' }}>
253
+ <OAuthDivider />
254
+ {/* Popup OAuth — never navigates the host. */}
255
+ <OAuthButtons providers={oauth.providers} onSelect={(provider) => {
256
+ setOauthError(null);
257
+ props.onBeforeAuth?.();
258
+ oauth.loginViaPopup(provider);
259
+ }}/>
260
+ </div>
261
+ </Show>
262
+ <button type="button" data-mol-id="auth-modal-switch" onClick={() => setMode(isSignup() ? 'login' : 'signup')} class={cm.cn(cm.button({ variant: 'ghost', size: 'sm' }))} style={{ 'margin-top': '12px', 'align-self': 'center' }}>
263
+ {isSignup()
264
+ ? t('auth.modal.haveAccount', undefined, {
265
+ defaultValue: 'Already have an account? Log in',
266
+ })
267
+ : t('auth.modal.needAccount', undefined, {
268
+ defaultValue: "Don't have an account? Sign up",
269
+ })}
270
+ </button>
271
+ </>}>
272
+ <div data-mol-id="auth-modal-success" style={{
273
+ display: 'flex',
274
+ 'flex-direction': 'column',
275
+ 'align-items': 'center',
276
+ gap: '10px',
277
+ // Written as cssstyle's own normalized form: React assigns the
278
+ // shorthand through the CSSOM property (which expands `0` to
279
+ // `0px`), Solid's setProperty keeps the string verbatim.
280
+ padding: '26px 0px 18px',
281
+ 'text-align': 'center',
282
+ }}>
283
+ <Icon name="check-circle" size={44} className={cm.textSuccess} aria-hidden="true"/>
284
+ <div style={{ 'font-size': '17px', 'font-weight': '600' }}>
285
+ {isSignup()
286
+ ? t('auth.modal.signedUp', undefined, { defaultValue: 'Signed up!' })
287
+ : t('auth.modal.loggedIn', undefined, { defaultValue: 'Logged in!' })}
288
+ </div>
289
+ <Who />
290
+ </div>
291
+ </Show>
292
+ </div>
293
+ </Modal>);
294
+ /**
295
+ * Who just authenticated — shown under the headline so the confirmation
296
+ * names the account, not just the outcome. Rendered only with the success
297
+ * view; reads the client synchronously (React reads it in the same render).
298
+ * @returns The muted "Logged in as …" line, or nothing.
299
+ */
300
+ function Who() {
301
+ const profile = authClient.getUser();
302
+ const who = profile?.name || profile?.email || profile?.username || '';
303
+ return (<Show when={who !== ''}>
304
+ <div class={cm.textMuted} style={{ 'font-size': '13px' }}>
305
+ {t('auth.modal.loggedInAs', { who }, { defaultValue: 'Logged in as {{who}}' })}
306
+ </div>
307
+ </Show>);
308
+ }
309
+ };
310
+ //# sourceMappingURL=AuthModal.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthModal.jsx","sourceRoot":"","sources":["../src/AuthModal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAEL,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,EAAE,EACF,SAAS,EACT,OAAO,EACP,IAAI,GACL,MAAM,UAAU,CAAA;AA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sBAAsB,EAAE,CAAC,CAChF;QAAA,EAAE,GAAG,CACP;MAAA,EAAE,IAAI,CAAC,CACR,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * One-mount in-app auth + upgrade flow for any Molecule app.
3
+ *
4
+ * Solid counterpart of `@molecule/app-auth-modal-react`'s `AuthModalMount`:
5
+ * the same props (React names), the same DOM for the same input, and the same
6
+ * navigation calls.
7
+ *
8
+ * Mount `<AuthModalMount oauthConfig={oauthConfig} />` once inside the app's
9
+ * providers (where the auth primitives work) and every in-app `/login` /
10
+ * `/signup` link opens the {@link AuthModal} instead of navigating, while
11
+ * `/pricing` / `/billing` links open the upgrade flow WITHOUT navigating the
12
+ * current tab — so the user never loses their place or work. By default the
13
+ * upgrade flow opens in a new tab, and on returning from that tab the session
14
+ * is refreshed in place so a completed upgrade reflects without a manual
15
+ * reload. A host that prefers to keep the user fully in place (e.g. an IDE
16
+ * showing pricing in its own modal) passes `onUpgradeIntercept` to receive the
17
+ * click instead — it then owns rendering the upgrade UI and refreshing the
18
+ * session afterwards.
19
+ *
20
+ * @module
21
+ */
22
+ import { type Component } from 'solid-js';
23
+ import { type AuthModalProps } from './AuthModal.jsx';
24
+ import { type AuthModalMode } from './cta-intercept.js';
25
+ /** Props for {@link AuthModalMount}. */
26
+ export interface AuthModalMountProps {
27
+ /** OAuth config from the app's `config.ts` (drives the popup OAuth buttons). */
28
+ oauthConfig: AuthModalProps['oauthConfig'];
29
+ /** Run before any login attempt (e.g. stash the guest id). Optional. */
30
+ onBeforeAuth?: () => void;
31
+ /** Run after a successful login (session already refreshed). Optional. */
32
+ onAuthenticated?: () => void | Promise<void>;
33
+ /**
34
+ * Run when the user returns to this tab after the upgrade tab (the session is
35
+ * already refreshed here) — e.g. invalidate usage so a budget banner clears.
36
+ * Only fires for the default new-tab flow; irrelevant when
37
+ * {@link AuthModalMountProps.onUpgradeIntercept} is set. Optional.
38
+ */
39
+ onUpgradeReturn?: () => void;
40
+ /**
41
+ * Take over upgrade/billing CTA clicks instead of opening a new tab: called
42
+ * with the matched upgrade path (e.g. `/pricing`), navigation already
43
+ * prevented. The host renders its own upgrade UI (typically a modal) and owns
44
+ * refreshing the session when that flow completes. Optional — when omitted,
45
+ * the default new-tab flow (+ focus-return refresh) applies.
46
+ */
47
+ onUpgradeIntercept?: (path: string) => void;
48
+ /**
49
+ * Human-verification challenge rendered inside the modal's SIGNUP form — see
50
+ * {@link AuthModalProps.captchaSlot}. Pass it together with
51
+ * {@link AuthModalMountProps.captchaSolved} whenever the app's signup API
52
+ * requires a challenge token, otherwise the in-app signup POSTs without one
53
+ * while the standalone `/signup` page (which renders its own widget) works —
54
+ * a mismatch the user experiences as "complete the challenge" with no
55
+ * challenge on screen. Optional.
56
+ */
57
+ captchaSlot?: AuthModalProps['captchaSlot'];
58
+ /** Whether {@link AuthModalMountProps.captchaSlot} is solved; `false` disables the signup submit. Defaults to `true`. */
59
+ captchaSolved?: boolean;
60
+ /** Override the auth path→mode map (defaults to `/login`,`/signup`). */
61
+ authPaths?: Readonly<Record<string, AuthModalMode>>;
62
+ /** Override the upgrade paths opened in a new tab (defaults to `/pricing`,`/billing`). */
63
+ upgradePaths?: readonly string[];
64
+ }
65
+ /**
66
+ * 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.
67
+ *
68
+ * @param props - {@link AuthModalMountProps}.
69
+ * @returns The (lazily-mounted) auth modal element.
70
+ */
71
+ export declare const AuthModalMount: Component<AuthModalMountProps>;
72
+ //# sourceMappingURL=AuthModalMount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthModalMount.d.ts","sourceRoot":"","sources":["../src/AuthModalMount.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,SAAS,EAA0C,MAAM,UAAU,CAAA;AAIjF,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,oBAAoB,CAAA;AAE3B,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,gFAAgF;IAChF,WAAW,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;IAC1C,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB,0EAA0E;IAC1E,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,IAAI,CAAA;IAC5B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,cAAc,CAAC,aAAa,CAAC,CAAA;IAC3C,yHAAyH;IACzH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,wEAAwE;IACxE,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAA;IACnD,0FAA0F;IAC1F,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,CAAC,mBAAmB,CAmFzD,CAAA"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * One-mount in-app auth + upgrade flow for any Molecule app.
3
+ *
4
+ * Solid counterpart of `@molecule/app-auth-modal-react`'s `AuthModalMount`:
5
+ * the same props (React names), the same DOM for the same input, and the same
6
+ * navigation calls.
7
+ *
8
+ * Mount `<AuthModalMount oauthConfig={oauthConfig} />` once inside the app's
9
+ * providers (where the auth primitives work) and every in-app `/login` /
10
+ * `/signup` link opens the {@link AuthModal} instead of navigating, while
11
+ * `/pricing` / `/billing` links open the upgrade flow WITHOUT navigating the
12
+ * current tab — so the user never loses their place or work. By default the
13
+ * upgrade flow opens in a new tab, and on returning from that tab the session
14
+ * is refreshed in place so a completed upgrade reflects without a manual
15
+ * reload. A host that prefers to keep the user fully in place (e.g. an IDE
16
+ * showing pricing in its own modal) passes `onUpgradeIntercept` to receive the
17
+ * click instead — it then owns rendering the upgrade UI and refreshing the
18
+ * session afterwards.
19
+ *
20
+ * @module
21
+ */
22
+ import { createSignal, onCleanup, onMount, Show } from 'solid-js';
23
+ import { useAuth } from '@molecule/app-solid';
24
+ import { AuthModal } from './AuthModal.jsx';
25
+ import { authModeForHref, DEFAULT_AUTH_PATHS, DEFAULT_UPGRADE_PATHS, upgradePathForHref, } from './cta-intercept.js';
26
+ /**
27
+ * 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.
28
+ *
29
+ * @param props - {@link AuthModalMountProps}.
30
+ * @returns The (lazily-mounted) auth modal element.
31
+ */
32
+ export const AuthModalMount = (props) => {
33
+ const { refresh } = useAuth();
34
+ const [open, setOpen] = createSignal(false);
35
+ const [mode, setMode] = createSignal('signup');
36
+ const openAuth = (next) => {
37
+ setMode(next);
38
+ setOpen(true);
39
+ };
40
+ // Set when the user opens the upgrade/billing flow in a new tab, so we refresh
41
+ // when they return (a completed upgrade reflects with no manual reload).
42
+ let upgradeTabOpened = false;
43
+ const onFocus = () => {
44
+ if (!upgradeTabOpened)
45
+ return;
46
+ upgradeTabOpened = false;
47
+ refresh().catch((_error) => {
48
+ // Best-effort freshness pass: the user may have returned without a
49
+ // session to refresh (never logged in, or the API has no refresh
50
+ // path) — not an error worth surfacing on a simple tab focus.
51
+ });
52
+ props.onUpgradeReturn?.();
53
+ };
54
+ // Intercept clicks on the in-app /login, /signup (→ modal) and /pricing, /billing
55
+ // (→ host's onUpgradeIntercept, else a new tab) CTAs — plain <a href> links from
56
+ // anywhere in the app, incl. ones opened with target="_blank". Capture-phase +
57
+ // preventDefault stops navigation. Plain left-clicks only — a modifier/middle
58
+ // click still opens the real page.
59
+ const onClick = (e) => {
60
+ if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
61
+ return;
62
+ const anchor = e.target?.closest('a[href]');
63
+ if (!anchor)
64
+ return;
65
+ const href = anchor.getAttribute('href');
66
+ const origin = window.location.origin;
67
+ const authMode = authModeForHref(href, origin, props.authPaths ?? DEFAULT_AUTH_PATHS);
68
+ if (authMode) {
69
+ e.preventDefault();
70
+ e.stopPropagation();
71
+ openAuth(authMode);
72
+ return;
73
+ }
74
+ const upgradePath = upgradePathForHref(href, origin, props.upgradePaths ?? DEFAULT_UPGRADE_PATHS);
75
+ if (upgradePath) {
76
+ e.preventDefault();
77
+ e.stopPropagation();
78
+ if (props.onUpgradeIntercept) {
79
+ props.onUpgradeIntercept(upgradePath);
80
+ return;
81
+ }
82
+ upgradeTabOpened = true;
83
+ window.open(upgradePath, '_blank', 'noopener,noreferrer');
84
+ }
85
+ };
86
+ onMount(() => {
87
+ window.addEventListener('focus', onFocus);
88
+ document.addEventListener('click', onClick, true);
89
+ });
90
+ onCleanup(() => {
91
+ window.removeEventListener('focus', onFocus);
92
+ document.removeEventListener('click', onClick, true);
93
+ });
94
+ // Mounted only while open so the auth primitives don't run on every app render.
95
+ return (<Show when={open()}>
96
+ <AuthModal open={open()} onClose={() => setOpen(false)} initialMode={mode()} oauthConfig={props.oauthConfig} onBeforeAuth={props.onBeforeAuth} onAuthenticated={props.onAuthenticated} captchaSlot={props.captchaSlot} captchaSolved={props.captchaSolved}/>
97
+ </Show>);
98
+ };
99
+ //# sourceMappingURL=AuthModalMount.jsx.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthModalMount.jsx","sourceRoot":"","sources":["../src/AuthModalMount.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;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A;QACzC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;IACF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAC5C,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;IACtD,CAAC,CAAC,CAAA;IAEF,gFAAgF;IAChF,OAAO,CACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CACjB;MAAA,CAAC,SAAS,CACR,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CACb,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAC9B,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC,CACpB,WAAW,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAC/B,YAAY,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CACjC,eAAe,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CACvC,WAAW,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAC/B,aAAa,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,EAEvC;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Pure routing decisions for the in-app auth/upgrade click-interceptor.
3
+ *
4
+ * A click on an in-app `/login` or `/signup` link opens the {@link AuthModal}
5
+ * instead of navigating; a click on `/pricing` or `/billing` opens the upgrade
6
+ * flow without navigating the current tab — the host's `onUpgradeIntercept`
7
+ * (e.g. an in-app modal) when provided, else a new tab. These helpers turn a
8
+ * clicked link's href into that decision so the interceptor stays trivial and
9
+ * unit-testable.
10
+ *
11
+ * @module
12
+ */
13
+ /** Which form {@link AuthModal} should show. */
14
+ export type AuthModalMode = 'login' | 'signup';
15
+ /** The default in-app auth routes that open the modal. */
16
+ export declare const DEFAULT_AUTH_PATHS: Readonly<Record<string, AuthModalMode>>;
17
+ /** The default routes that open the upgrade/billing flow (modal or new tab). */
18
+ export declare const DEFAULT_UPGRADE_PATHS: readonly string[];
19
+ /**
20
+ * Map a CTA link's href to the auth mode it should open, or `null` if it is not
21
+ * an auth link (so the interceptor leaves it alone).
22
+ *
23
+ * @param href - The clicked anchor's href (relative or absolute).
24
+ * @param origin - The page origin to resolve a relative href against.
25
+ * @param authPaths - Path→mode map (defaults to {@link DEFAULT_AUTH_PATHS}).
26
+ * @returns `'login'` / `'signup'`, else `null`.
27
+ */
28
+ export declare function authModeForHref(href: string | null | undefined, origin: string, authPaths?: Readonly<Record<string, AuthModalMode>>): AuthModalMode | null;
29
+ /**
30
+ * Whether a CTA link's href points at the upgrade/billing flow (which the
31
+ * interceptor hands to the host's `onUpgradeIntercept`, else opens in a new tab).
32
+ *
33
+ * @param href - The clicked anchor's href (relative or absolute).
34
+ * @param origin - The page origin to resolve a relative href against.
35
+ * @param upgradePaths - The upgrade paths (defaults to {@link DEFAULT_UPGRADE_PATHS}).
36
+ * @returns The matched pathname, else `null`.
37
+ */
38
+ export declare function upgradePathForHref(href: string | null | undefined, origin: string, upgradePaths?: readonly string[]): string | null;
39
+ //# sourceMappingURL=cta-intercept.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cta-intercept.d.ts","sourceRoot":"","sources":["../src/cta-intercept.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,gDAAgD;AAChD,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,CAAA;AAE9C,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAGtE,CAAA;AAED,gFAAgF;AAChF,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAA6B,CAAA;AAahF;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAsB,GACtE,aAAa,GAAG,IAAI,CAGtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,MAAM,EAAE,MAAM,EACd,YAAY,GAAE,SAAS,MAAM,EAA0B,GACtD,MAAM,GAAG,IAAI,CAGf"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Pure routing decisions for the in-app auth/upgrade click-interceptor.
3
+ *
4
+ * A click on an in-app `/login` or `/signup` link opens the {@link AuthModal}
5
+ * instead of navigating; a click on `/pricing` or `/billing` opens the upgrade
6
+ * flow without navigating the current tab — the host's `onUpgradeIntercept`
7
+ * (e.g. an in-app modal) when provided, else a new tab. These helpers turn a
8
+ * clicked link's href into that decision so the interceptor stays trivial and
9
+ * unit-testable.
10
+ *
11
+ * @module
12
+ */
13
+ /** The default in-app auth routes that open the modal. */
14
+ export const DEFAULT_AUTH_PATHS = {
15
+ '/login': 'login',
16
+ '/signup': 'signup',
17
+ };
18
+ /** The default routes that open the upgrade/billing flow (modal or new tab). */
19
+ export const DEFAULT_UPGRADE_PATHS = ['/pricing', '/billing'];
20
+ /** Resolve an href to its pathname against `origin`, or `null` if malformed. */
21
+ function pathOf(href, origin) {
22
+ if (!href)
23
+ return null;
24
+ try {
25
+ return new URL(href, origin).pathname;
26
+ }
27
+ catch (_error) {
28
+ // A malformed href is not an in-app CTA — leave it alone (intentional noop).
29
+ return null;
30
+ }
31
+ }
32
+ /**
33
+ * Map a CTA link's href to the auth mode it should open, or `null` if it is not
34
+ * an auth link (so the interceptor leaves it alone).
35
+ *
36
+ * @param href - The clicked anchor's href (relative or absolute).
37
+ * @param origin - The page origin to resolve a relative href against.
38
+ * @param authPaths - Path→mode map (defaults to {@link DEFAULT_AUTH_PATHS}).
39
+ * @returns `'login'` / `'signup'`, else `null`.
40
+ */
41
+ export function authModeForHref(href, origin, authPaths = DEFAULT_AUTH_PATHS) {
42
+ const path = pathOf(href, origin);
43
+ return path != null ? (authPaths[path] ?? null) : null;
44
+ }
45
+ /**
46
+ * Whether a CTA link's href points at the upgrade/billing flow (which the
47
+ * interceptor hands to the host's `onUpgradeIntercept`, else opens in a new tab).
48
+ *
49
+ * @param href - The clicked anchor's href (relative or absolute).
50
+ * @param origin - The page origin to resolve a relative href against.
51
+ * @param upgradePaths - The upgrade paths (defaults to {@link DEFAULT_UPGRADE_PATHS}).
52
+ * @returns The matched pathname, else `null`.
53
+ */
54
+ export function upgradePathForHref(href, origin, upgradePaths = DEFAULT_UPGRADE_PATHS) {
55
+ const path = pathOf(href, origin);
56
+ return path != null && upgradePaths.includes(path) ? path : null;
57
+ }
58
+ //# sourceMappingURL=cta-intercept.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cta-intercept.js","sourceRoot":"","sources":["../src/cta-intercept.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,kBAAkB,GAA4C;IACzE,QAAQ,EAAE,OAAO;IACjB,SAAS,EAAE,QAAQ;CACpB,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,qBAAqB,GAAsB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;AAEhF,gFAAgF;AAChF,SAAS,MAAM,CAAC,IAA+B,EAAE,MAAc;IAC7D,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAA;IACtB,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAA;IACvC,CAAC;IAAC,OAAO,MAAM,EAAE,CAAC;QAChB,6EAA6E;QAC7E,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;;;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