@molecule/app-auth-modal-solid 0.0.0-stage → 0.0.1-stage
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.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/AuthModal.d.ts +76 -0
- package/dist/AuthModal.d.ts.map +1 -0
- package/dist/AuthModal.jsx +310 -0
- package/dist/AuthModal.jsx.map +1 -0
- package/dist/AuthModalMount.d.ts +72 -0
- package/dist/AuthModalMount.d.ts.map +1 -0
- package/dist/AuthModalMount.jsx +99 -0
- package/dist/AuthModalMount.jsx.map +1 -0
- package/dist/cta-intercept.d.ts +39 -0
- package/dist/cta-intercept.d.ts.map +1 -0
- package/dist/cta-intercept.js +58 -0
- package/dist/cta-intercept.js.map +1 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @molecule/app-auth-modal-solid
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @molecule/app-auth-modal-solid
|
|
7
|
+
```
|
|
8
|
+
|
|
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.
|
|
10
|
+
|
|
11
|
+
License: Apache-2.0
|
|
@@ -0,0 +1,76 @@
|
|
|
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 type { JSX } from 'solid-js';
|
|
19
|
+
import { type Component } from 'solid-js';
|
|
20
|
+
import { type UseOAuthConfig } from '@molecule/app-solid';
|
|
21
|
+
import type { AuthModalMode } from './cta-intercept.js';
|
|
22
|
+
/** Props for {@link AuthModal}. */
|
|
23
|
+
export interface AuthModalProps {
|
|
24
|
+
/** Whether the modal is open. */
|
|
25
|
+
open: boolean;
|
|
26
|
+
/** Close without authenticating (backdrop / Escape / ✕). */
|
|
27
|
+
onClose?: () => void;
|
|
28
|
+
/** Which form to open on. Defaults to `'signup'`. */
|
|
29
|
+
initialMode?: AuthModalMode;
|
|
30
|
+
/**
|
|
31
|
+
* OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
|
|
32
|
+
* from the app's `config.ts`. Drives the popup OAuth buttons.
|
|
33
|
+
*/
|
|
34
|
+
oauthConfig: UseOAuthConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the guest
|
|
37
|
+
* id so the new session can claim its work. Optional.
|
|
38
|
+
*/
|
|
39
|
+
onBeforeAuth?: () => void;
|
|
40
|
+
/**
|
|
41
|
+
* Run AFTER a successful login/signup/OAuth (the session is already refreshed),
|
|
42
|
+
* still on the same page — e.g. claim guest projects, invalidate usage. Optional.
|
|
43
|
+
*/
|
|
44
|
+
onAuthenticated?: () => void | Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* A human-verification challenge rendered inside the SIGNUP form, above the
|
|
47
|
+
* submit button (e.g. the app's Turnstile/hCaptcha widget). Login is not
|
|
48
|
+
* gated, so the slot is unmounted in login mode — which lets the widget clear
|
|
49
|
+
* its own token when the user switches tabs and re-issue a fresh one on the
|
|
50
|
+
* way back.
|
|
51
|
+
*
|
|
52
|
+
* The modal stays provider-agnostic: it renders the node and never inspects
|
|
53
|
+
* it. An app whose signup API requires a challenge MUST pass
|
|
54
|
+
* {@link AuthModalProps.captchaSolved} as well, or the form will submit
|
|
55
|
+
* without a token and the API will reject it.
|
|
56
|
+
*
|
|
57
|
+
* Optional — omitted (the default for apps with no challenge) the signup form
|
|
58
|
+
* is unchanged.
|
|
59
|
+
*/
|
|
60
|
+
captchaSlot?: JSX.Element;
|
|
61
|
+
/**
|
|
62
|
+
* Whether the {@link AuthModalProps.captchaSlot} challenge is currently
|
|
63
|
+
* solved. `false` disables the signup submit, so the form cannot POST a
|
|
64
|
+
* missing/expired token. Defaults to `true` (no challenge → nothing to wait
|
|
65
|
+
* for). Ignored in login mode.
|
|
66
|
+
*/
|
|
67
|
+
captchaSolved?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 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.
|
|
71
|
+
*
|
|
72
|
+
* @param props - {@link AuthModalProps}.
|
|
73
|
+
* @returns The modal element (renders nothing when closed).
|
|
74
|
+
*/
|
|
75
|
+
export declare const AuthModal: Component<AuthModalProps>;
|
|
76
|
+
//# sourceMappingURL=AuthModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthModal.d.ts","sourceRoot":"","sources":["../src/AuthModal.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,EACL,KAAK,SAAS,EAQf,MAAM,UAAU,CAAA;AAIjB,OAAO,EAML,KAAK,cAAc,EAGpB,MAAM,qBAAqB,CAAA;AAI5B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAoDvD,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,iCAAiC;IACjC,IAAI,EAAE,OAAO,CAAA;IACb,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,qDAAqD;IACrD,WAAW,CAAC,EAAE,aAAa,CAAA;IAC3B;;;OAGG;IACH,WAAW,EAAE,cAAc,CAAA;IAC3B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C;;;;;;;;;;;;;;OAcG;IACH,WAAW,CAAC,EAAE,GAAG,CAAC,OAAO,CAAA;IACzB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,SAAS,CAAC,cAAc,CAuU/C,CAAA"}
|
|
@@ -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;AAEjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAC9E,OAAO,EACL,OAAO,EACP,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EAER,SAAS,EACT,cAAc,GACf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAI5D;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,uCAAuC,CAAA;AAEjE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAS/B;;;;;;GAMG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,CAAC,CAAC,CAAC,qBAAqB,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC,CACzE;YAAA,EAAE,GAAG,CACL;YAAA,CAAC,GAAG,CAAC,AAAD,EACN;UAAA,EAAE,GAAG,CACP;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,GAAG,CACP;IAAA,EAAE,KAAK,CAAC,CACT,CAAA;IAED;;;;;OAKG;IACH,SAAS,GAAG;QACV,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,EAA2B,CAAA;QAC7D,MAAM,GAAG,GAAG,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAA;QACtE,OAAO,CACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,CACrB;QAAA,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CACvD;UAAA,CAAC,CAAC,CAAC,uBAAuB,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,YAAY,EAAE,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;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAkB,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAEjF,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAuB,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAEL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AA2C3B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAmC,CAAC,KAAK,EAAE,EAAE;IACtE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAA;IAC7B,M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E,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;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,IAA+B,EAC/B,MAAc,EACd,YAAqD,kBAAkB;IAEvE,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACjC,OAAO,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAA+B,EAC/B,MAAc,EACd,eAAkC,qBAAqB;IAEvD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACjC,OAAO,IAAI,IAAI,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAA;AAClE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-modal-solid` — the shared in-app login / signup /
|
|
3
|
+
* upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
|
|
4
|
+
* providers (where the `@molecule/app-solid` auth primitives work) and every
|
|
5
|
+
* in-app `/login` / `/signup` link opens the {@link AuthModal} instead of
|
|
6
|
+
* navigating, while `/pricing` / `/billing` links open the upgrade flow in
|
|
7
|
+
* a new tab (session auto-refreshes when the user returns) — no
|
|
8
|
+
* navigation, no reload, no lost work. OAuth runs in a popup
|
|
9
|
+
* (`loginViaPopup`), so social login never navigates the host either.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { render } from 'solid-js/web'
|
|
14
|
+
* import { AuthModalMount } from '@molecule/app-auth-modal-solid'
|
|
15
|
+
* import { oauthConfig } from './config.jsx'
|
|
16
|
+
*
|
|
17
|
+
* // Once, inside the app's providers (e.g. in App.tsx):
|
|
18
|
+
* <AuthModalMount oauthConfig={oauthConfig} onAuthenticated={() => claimGuestWork()} />
|
|
19
|
+
* // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
|
|
20
|
+
* // anywhere in the app is now intercepted — no other wiring needed.
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Interception is capture-phase on `document` and matches plain
|
|
25
|
+
* left-clicks on `<a href>` whose resolved pathname is in `authPaths`
|
|
26
|
+
* (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
|
|
27
|
+
* `/billing`) — modifier/middle clicks still navigate normally, and
|
|
28
|
+
* non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
|
|
29
|
+
* that render pricing in-place pass `onUpgradeIntercept` and own that UI
|
|
30
|
+
* + the post-upgrade session refresh. `AuthModalMount` must render inside
|
|
31
|
+
* the app's auth/HTTP providers (it calls `useAuth`), and the standalone
|
|
32
|
+
* `/login` & `/signup` pages should stay routed — they are the fallback
|
|
33
|
+
* for modifier clicks and deep links. App-specific extras (stash a guest
|
|
34
|
+
* id, claim guest work, invalidate usage) go in `onBeforeAuth` /
|
|
35
|
+
* `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
|
|
36
|
+
* `@molecule/app-locales-common` bond (79 languages), alongside the
|
|
37
|
+
* `auth.login.*` / `auth.signup.*` keys the modal also renders.
|
|
38
|
+
*
|
|
39
|
+
* If the signup API requires a human-verification challenge (Turnstile /
|
|
40
|
+
* hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
|
|
41
|
+
* form) and `captchaSolved` (which gates the submit). Rendering the widget
|
|
42
|
+
* on the standalone `/signup` page alone is NOT enough: this modal is what
|
|
43
|
+
* a `/signup` link actually opens, so the in-app signup would POST with no
|
|
44
|
+
* token and the API would answer "complete the verification challenge"
|
|
45
|
+
* while no challenge is on screen. Login is not gated, so the slot is
|
|
46
|
+
* unmounted in login mode.
|
|
47
|
+
*
|
|
48
|
+
* @module
|
|
49
|
+
*/
|
|
50
|
+
export * from './AuthModal.jsx';
|
|
51
|
+
export * from './AuthModalMount.jsx';
|
|
52
|
+
export * from './cta-intercept.js';
|
|
53
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-modal-solid` — the shared in-app login / signup /
|
|
3
|
+
* upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
|
|
4
|
+
* providers (where the `@molecule/app-solid` auth primitives work) and every
|
|
5
|
+
* in-app `/login` / `/signup` link opens the {@link AuthModal} instead of
|
|
6
|
+
* navigating, while `/pricing` / `/billing` links open the upgrade flow in
|
|
7
|
+
* a new tab (session auto-refreshes when the user returns) — no
|
|
8
|
+
* navigation, no reload, no lost work. OAuth runs in a popup
|
|
9
|
+
* (`loginViaPopup`), so social login never navigates the host either.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { render } from 'solid-js/web'
|
|
14
|
+
* import { AuthModalMount } from '@molecule/app-auth-modal-solid'
|
|
15
|
+
* import { oauthConfig } from './config.jsx'
|
|
16
|
+
*
|
|
17
|
+
* // Once, inside the app's providers (e.g. in App.tsx):
|
|
18
|
+
* <AuthModalMount oauthConfig={oauthConfig} onAuthenticated={() => claimGuestWork()} />
|
|
19
|
+
* // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
|
|
20
|
+
* // anywhere in the app is now intercepted — no other wiring needed.
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Interception is capture-phase on `document` and matches plain
|
|
25
|
+
* left-clicks on `<a href>` whose resolved pathname is in `authPaths`
|
|
26
|
+
* (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
|
|
27
|
+
* `/billing`) — modifier/middle clicks still navigate normally, and
|
|
28
|
+
* non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
|
|
29
|
+
* that render pricing in-place pass `onUpgradeIntercept` and own that UI
|
|
30
|
+
* + the post-upgrade session refresh. `AuthModalMount` must render inside
|
|
31
|
+
* the app's auth/HTTP providers (it calls `useAuth`), and the standalone
|
|
32
|
+
* `/login` & `/signup` pages should stay routed — they are the fallback
|
|
33
|
+
* for modifier clicks and deep links. App-specific extras (stash a guest
|
|
34
|
+
* id, claim guest work, invalidate usage) go in `onBeforeAuth` /
|
|
35
|
+
* `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
|
|
36
|
+
* `@molecule/app-locales-common` bond (79 languages), alongside the
|
|
37
|
+
* `auth.login.*` / `auth.signup.*` keys the modal also renders.
|
|
38
|
+
*
|
|
39
|
+
* If the signup API requires a human-verification challenge (Turnstile /
|
|
40
|
+
* hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
|
|
41
|
+
* form) and `captchaSolved` (which gates the submit). Rendering the widget
|
|
42
|
+
* on the standalone `/signup` page alone is NOT enough: this modal is what
|
|
43
|
+
* a `/signup` link actually opens, so the in-app signup would POST with no
|
|
44
|
+
* token and the API would answer "complete the verification challenge"
|
|
45
|
+
* while no challenge is on screen. Login is not gated, so the slot is
|
|
46
|
+
* unmounted in login mode.
|
|
47
|
+
*
|
|
48
|
+
* @module
|
|
49
|
+
*/
|
|
50
|
+
export * from './AuthModal.jsx';
|
|
51
|
+
export * from './AuthModalMount.jsx';
|
|
52
|
+
export * from './cta-intercept.js';
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-auth-modal-solid",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-stage",
|
|
4
|
+
"description": "In-app login / signup modal + click-interceptor + popup OAuth — authenticate and upgrade without ever navigating away or losing work",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-auth-modal-solid",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"molecule",
|
|
27
|
+
"auth",
|
|
28
|
+
"login",
|
|
29
|
+
"signup",
|
|
30
|
+
"modal",
|
|
31
|
+
"oauth",
|
|
32
|
+
"solid"
|
|
33
|
+
],
|
|
34
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
39
|
+
"directory": "packages/app/features/auth-modal-solid"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@molecule/app-auth-shell-solid": "^1.0.0",
|
|
50
|
+
"@molecule/app-i18n": "^1.0.1",
|
|
51
|
+
"@molecule/app-oauth-buttons-solid": "^1.0.0",
|
|
52
|
+
"@molecule/app-solid": "^3.5.0",
|
|
53
|
+
"@molecule/app-ui": "^1.0.1",
|
|
54
|
+
"@molecule/app-ui-solid": "^1.1.0",
|
|
55
|
+
"solid-js": "^1.8.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@molecule/app-auth-shell-solid": "1.0.0",
|
|
59
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
60
|
+
"@molecule/app-i18n": "1.2.2",
|
|
61
|
+
"@molecule/app-icons": "1.0.4",
|
|
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",
|
|
66
|
+
"@types/node": "26.6.5",
|
|
67
|
+
"jsdom": "30.1.3",
|
|
68
|
+
"solid-js": "1.9.17",
|
|
69
|
+
"typescript": "6.0.3",
|
|
70
|
+
"vite-plugin-solid": "2.11.15",
|
|
71
|
+
"vitest": "4.1.12"
|
|
72
|
+
}
|
|
73
|
+
}
|