@molecule/app-auth-modal-vue 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.
- package/LICENSE +202 -0
- package/README.md +384 -2
- package/dist/AuthModal.d.ts +114 -0
- package/dist/AuthModal.d.ts.map +1 -0
- package/dist/AuthModal.js +408 -0
- package/dist/AuthModal.js.map +1 -0
- package/dist/AuthModalMount.d.ts +114 -0
- package/dist/AuthModalMount.d.ts.map +1 -0
- package/dist/AuthModalMount.js +127 -0
- package/dist/AuthModalMount.js.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 +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-app login / signup modal — authenticate WITHOUT leaving the page.
|
|
3
|
+
*
|
|
4
|
+
* Vue counterpart of `@molecule/app-auth-modal-react`'s `AuthModal`: the same
|
|
5
|
+
* props (React names), the same ClassMap tokens, the same i18n keys, and the
|
|
6
|
+
* same DOM for the same input.
|
|
7
|
+
*
|
|
8
|
+
* Reuses the Vue auth composables (`useLogin` / `useSignup` / `useOAuth` /
|
|
9
|
+
* `useAuth`) so behavior matches the standalone `/login` and `/signup` pages, but
|
|
10
|
+
* on success it stays in place: it refreshes the session (so guards + plan are
|
|
11
|
+
* current), runs an optional app `onAuthenticated` hook (e.g. claim guest work,
|
|
12
|
+
* invalidate usage), and closes — no navigation, no reload. OAuth runs in a POPUP
|
|
13
|
+
* (`loginViaPopup`) so social login never navigates the host either.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { type PropType, type VNode, type VNodeChild } from 'vue';
|
|
18
|
+
import { type UseOAuthConfig } from '@molecule/app-vue';
|
|
19
|
+
import type { AuthModalMode } from './cta-intercept.js';
|
|
20
|
+
/** Props for {@link AuthModal}. */
|
|
21
|
+
export interface AuthModalProps {
|
|
22
|
+
/** Whether the modal is open. */
|
|
23
|
+
open: boolean;
|
|
24
|
+
/** Close without authenticating (backdrop / Escape / ✕). */
|
|
25
|
+
onClose?: () => void;
|
|
26
|
+
/** Which form to open on. Defaults to `'signup'`. */
|
|
27
|
+
initialMode?: AuthModalMode;
|
|
28
|
+
/**
|
|
29
|
+
* OAuth config consumed by `useOAuth()` — `{ baseURL, oauthProviders, oauthEndpoint }`
|
|
30
|
+
* from the app's `config.ts`. Drives the popup OAuth buttons.
|
|
31
|
+
*/
|
|
32
|
+
oauthConfig: UseOAuthConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Run synchronously BEFORE any login/signup/OAuth attempt — e.g. stash the guest
|
|
35
|
+
* id so the new session can claim its work. Optional.
|
|
36
|
+
*/
|
|
37
|
+
onBeforeAuth?: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Run AFTER a successful login/signup/OAuth (the session is already refreshed),
|
|
40
|
+
* still on the same page — e.g. claim guest projects, invalidate usage. Optional.
|
|
41
|
+
*/
|
|
42
|
+
onAuthenticated?: () => void | Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* A human-verification challenge rendered inside the SIGNUP form, above the
|
|
45
|
+
* submit button (e.g. the app's Turnstile/hCaptcha widget). Login is not
|
|
46
|
+
* gated, so the slot is unmounted in login mode — which lets the widget clear
|
|
47
|
+
* its own token when the user switches tabs and re-issue a fresh one on the
|
|
48
|
+
* way back. Passed as a prop or as the same-named slot.
|
|
49
|
+
*
|
|
50
|
+
* The modal stays provider-agnostic: it renders the node and never inspects
|
|
51
|
+
* it. An app whose signup API requires a challenge MUST pass
|
|
52
|
+
* {@link AuthModalProps.captchaSolved} as well, or the form will submit
|
|
53
|
+
* without a token and the API will reject it.
|
|
54
|
+
*
|
|
55
|
+
* Optional — omitted (the default for apps with no challenge) the signup form
|
|
56
|
+
* is unchanged.
|
|
57
|
+
*/
|
|
58
|
+
captchaSlot?: VNodeChild | null;
|
|
59
|
+
/**
|
|
60
|
+
* Whether the {@link AuthModalProps.captchaSlot} challenge is currently
|
|
61
|
+
* solved. `false` disables the signup submit, so the form cannot POST a
|
|
62
|
+
* missing/expired token. Defaults to `true` (no challenge → nothing to wait
|
|
63
|
+
* for). Ignored in login mode.
|
|
64
|
+
*/
|
|
65
|
+
captchaSolved?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 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.
|
|
69
|
+
*
|
|
70
|
+
* @param props - {@link AuthModalProps}.
|
|
71
|
+
* @returns The modal component (renders nothing when closed).
|
|
72
|
+
*/
|
|
73
|
+
export declare const AuthModal: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
74
|
+
open: {
|
|
75
|
+
type: BooleanConstructor;
|
|
76
|
+
default: boolean;
|
|
77
|
+
};
|
|
78
|
+
onClose: PropType<() => void>;
|
|
79
|
+
initialMode: {
|
|
80
|
+
type: PropType<AuthModalMode>;
|
|
81
|
+
default: string;
|
|
82
|
+
};
|
|
83
|
+
oauthConfig: null;
|
|
84
|
+
onBeforeAuth: PropType<() => void>;
|
|
85
|
+
onAuthenticated: PropType<() => void | Promise<void>>;
|
|
86
|
+
captchaSlot: null;
|
|
87
|
+
captchaSolved: {
|
|
88
|
+
type: BooleanConstructor;
|
|
89
|
+
default: boolean;
|
|
90
|
+
};
|
|
91
|
+
}>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
92
|
+
open: {
|
|
93
|
+
type: BooleanConstructor;
|
|
94
|
+
default: boolean;
|
|
95
|
+
};
|
|
96
|
+
onClose: PropType<() => void>;
|
|
97
|
+
initialMode: {
|
|
98
|
+
type: PropType<AuthModalMode>;
|
|
99
|
+
default: string;
|
|
100
|
+
};
|
|
101
|
+
oauthConfig: null;
|
|
102
|
+
onBeforeAuth: PropType<() => void>;
|
|
103
|
+
onAuthenticated: PropType<() => void | Promise<void>>;
|
|
104
|
+
captchaSlot: null;
|
|
105
|
+
captchaSolved: {
|
|
106
|
+
type: BooleanConstructor;
|
|
107
|
+
default: boolean;
|
|
108
|
+
};
|
|
109
|
+
}>> & Readonly<{}>, {
|
|
110
|
+
open: boolean;
|
|
111
|
+
initialMode: AuthModalMode;
|
|
112
|
+
captchaSolved: boolean;
|
|
113
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
114
|
+
//# sourceMappingURL=AuthModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthModal.d.ts","sourceRoot":"","sources":["../src/AuthModal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAOL,KAAK,QAAQ,EAEb,KAAK,KAAK,EACV,KAAK,UAAU,EAEhB,MAAM,KAAK,CAAA;AAMZ,OAAO,EAML,KAAK,cAAc,EAGpB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAwDvD,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,UAAU,GAAG,IAAI,CAAA;IAC/B;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,SAAS;;;;;aAIG,QAAQ,CAAC,MAAM,IAAI,CAAC;;cAEvB,QAAQ,CAAC,aAAa,CAAC;;;;kBAIf,QAAQ,CAAC,MAAM,IAAI,CAAC;qBACjB,QAAQ,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;;;;;;UA4HtD,KAAK;;;;;aAnIK,QAAQ,CAAC,MAAM,IAAI,CAAC;;cAEvB,QAAQ,CAAC,aAAa,CAAC;;;;kBAIf,QAAQ,CAAC,MAAM,IAAI,CAAC;qBACjB,QAAQ,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;;;;;;;;;;4EAkYnE,CAAA"}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-app login / signup modal — authenticate WITHOUT leaving the page.
|
|
3
|
+
*
|
|
4
|
+
* Vue counterpart of `@molecule/app-auth-modal-react`'s `AuthModal`: the same
|
|
5
|
+
* props (React names), the same ClassMap tokens, the same i18n keys, and the
|
|
6
|
+
* same DOM for the same input.
|
|
7
|
+
*
|
|
8
|
+
* Reuses the Vue auth composables (`useLogin` / `useSignup` / `useOAuth` /
|
|
9
|
+
* `useAuth`) so behavior matches the standalone `/login` and `/signup` pages, but
|
|
10
|
+
* on success it stays in place: it refreshes the session (so guards + plan are
|
|
11
|
+
* current), runs an optional app `onAuthenticated` hook (e.g. claim guest work,
|
|
12
|
+
* invalidate usage), and closes — no navigation, no reload. OAuth runs in a POPUP
|
|
13
|
+
* (`loginViaPopup`) so social login never navigates the host either.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import { computed, defineComponent, h, nextTick, onMounted, onScopeDispose, ref, watch, } from 'vue';
|
|
18
|
+
import { useAuthFormState } from '@molecule/app-auth-shell-vue';
|
|
19
|
+
import { OAuthButtons, OAuthDivider } from '@molecule/app-oauth-buttons-vue';
|
|
20
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
21
|
+
import { Button, Icon, Modal } from '@molecule/app-ui-vue';
|
|
22
|
+
import { useAuth, useAuthClient, useI18nError, useLogin, useOAuth, useSignup, useTranslation, } from '@molecule/app-vue';
|
|
23
|
+
/**
|
|
24
|
+
* Matches phones (narrow viewport) OR touch-first devices (coarse primary
|
|
25
|
+
* pointer) — the contexts where a sub-16px input font makes iOS Safari zoom
|
|
26
|
+
* the whole page on focus.
|
|
27
|
+
*/
|
|
28
|
+
const TOUCH_FIRST_QUERY = '(max-width: 767px), (pointer: coarse)';
|
|
29
|
+
/**
|
|
30
|
+
* How long the "Signed up!" / "Logged in!" confirmation stays visible before
|
|
31
|
+
* the modal closes. Long enough to register, short enough not to feel like a
|
|
32
|
+
* wait — and the app's `onAuthenticated` work (claiming guest projects etc.)
|
|
33
|
+
* runs concurrently, so the real delay is `max(this, onAuthenticated)`.
|
|
34
|
+
*/
|
|
35
|
+
const SUCCESS_DISPLAY_MS = 1000;
|
|
36
|
+
/**
|
|
37
|
+
* Whether {@link TOUCH_FIRST_QUERY} currently matches. SSR-safe (reports
|
|
38
|
+
* `false` until mounted in a browser) and subscribes to media-query changes
|
|
39
|
+
* (rotation, window resize across the breakpoint). Local to this package — it
|
|
40
|
+
* must not import IDE feature composables for a two-line media-query check.
|
|
41
|
+
* @returns True on phone-width or touch-first devices.
|
|
42
|
+
*/
|
|
43
|
+
function useTouchFirstViewport() {
|
|
44
|
+
const matches = ref(typeof window !== 'undefined' &&
|
|
45
|
+
typeof window.matchMedia === 'function' &&
|
|
46
|
+
window.matchMedia(TOUCH_FIRST_QUERY).matches);
|
|
47
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
48
|
+
const mql = window.matchMedia(TOUCH_FIRST_QUERY);
|
|
49
|
+
// React's effect re-reads `mql.matches` on mount before subscribing; the
|
|
50
|
+
// setup value above is that same read.
|
|
51
|
+
matches.value = mql.matches;
|
|
52
|
+
const onChange = (e) => {
|
|
53
|
+
matches.value = e.matches;
|
|
54
|
+
};
|
|
55
|
+
mql.addEventListener('change', onChange);
|
|
56
|
+
onScopeDispose(() => {
|
|
57
|
+
mql.removeEventListener('change', onChange);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return matches;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 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.
|
|
64
|
+
*
|
|
65
|
+
* @param props - {@link AuthModalProps}.
|
|
66
|
+
* @returns The modal component (renders nothing when closed).
|
|
67
|
+
*/
|
|
68
|
+
export const AuthModal = defineComponent({
|
|
69
|
+
name: 'AuthModal',
|
|
70
|
+
props: {
|
|
71
|
+
open: { type: Boolean, default: false },
|
|
72
|
+
onClose: Function,
|
|
73
|
+
initialMode: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: 'signup',
|
|
76
|
+
},
|
|
77
|
+
oauthConfig: null,
|
|
78
|
+
onBeforeAuth: Function,
|
|
79
|
+
onAuthenticated: Function,
|
|
80
|
+
captchaSlot: null,
|
|
81
|
+
captchaSolved: { type: Boolean, default: true },
|
|
82
|
+
},
|
|
83
|
+
setup(props, { slots }) {
|
|
84
|
+
const { t } = useTranslation();
|
|
85
|
+
const cm = getClassMap();
|
|
86
|
+
const isTouchFirst = useTouchFirstViewport();
|
|
87
|
+
// React's `useState(initialMode)`: read once, then owned by the component.
|
|
88
|
+
const mode = ref(props.initialMode);
|
|
89
|
+
const { refresh } = useAuth();
|
|
90
|
+
const authClient = useAuthClient();
|
|
91
|
+
const { status: loginStatus, error: loginError, login } = useLogin();
|
|
92
|
+
const { status: signupStatus, error: signupError, signup } = useSignup();
|
|
93
|
+
const { fields, setField, clear } = useAuthFormState();
|
|
94
|
+
const password = ref('');
|
|
95
|
+
const name = ref('');
|
|
96
|
+
const twoFactorToken = ref('');
|
|
97
|
+
const oauthError = ref(null);
|
|
98
|
+
// Post-auth confirmation ("Signed up!" / "Logged in!") shown briefly before
|
|
99
|
+
// the modal closes — without it the modal just vanished, which read as
|
|
100
|
+
// "nothing happened".
|
|
101
|
+
const succeeded = ref(false);
|
|
102
|
+
const isSignup = computed(() => mode.value === 'signup');
|
|
103
|
+
const busy = computed(() => isSignup.value ? signupStatus.value === 'pending' : loginStatus.value === 'pending');
|
|
104
|
+
const errorMessage = useI18nError(() => (isSignup.value ? signupError.value : loginError.value));
|
|
105
|
+
// Dialog pattern (WAI-ARIA): when the modal opens, keyboard and
|
|
106
|
+
// screen-reader users land on the form's primary field instead of on the
|
|
107
|
+
// page behind the overlay. This replaces the `autofocus` attribute, which
|
|
108
|
+
// jsx-a11y/no-autofocus bars: the attribute fires on EVERY mount of the
|
|
109
|
+
// input (e.g. the brief remount after the mode switches), while these two
|
|
110
|
+
// paths run exactly once per open transition — mount, and a later
|
|
111
|
+
// open flip. The mount path runs after the Modal's own focus-trap
|
|
112
|
+
// bookkeeping (child mounted hooks first, React's child-effects-first
|
|
113
|
+
// ordering); the flip path resolves after it in the same flush. The email
|
|
114
|
+
// field wins in both signup and login mode.
|
|
115
|
+
const emailRef = ref(null);
|
|
116
|
+
const focusEmail = () => {
|
|
117
|
+
if (props.open)
|
|
118
|
+
emailRef.value?.focus();
|
|
119
|
+
};
|
|
120
|
+
const focusEmailWhenPatched = () => {
|
|
121
|
+
void nextTick(focusEmail);
|
|
122
|
+
};
|
|
123
|
+
watch(() => props.open, (open) => {
|
|
124
|
+
if (open)
|
|
125
|
+
focusEmailWhenPatched();
|
|
126
|
+
});
|
|
127
|
+
onMounted(focusEmail);
|
|
128
|
+
// Universal post-auth: refresh the session (guards + plan current), show a
|
|
129
|
+
// brief confirmation, run the app's hook, then close — all in place, no
|
|
130
|
+
// navigation.
|
|
131
|
+
const finishAuth = async () => {
|
|
132
|
+
try {
|
|
133
|
+
await refresh();
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
// Every path into finishAuth (password login/signup response, OAuth popup
|
|
137
|
+
// relay) has already established the session client-side, so the refresh
|
|
138
|
+
// is a freshness pass — a failure here (e.g. an API with neither a
|
|
139
|
+
// refresh endpoint nor cookie restore) must NOT strand an authenticated
|
|
140
|
+
// user in the modal with their account already created. Only a genuinely
|
|
141
|
+
// absent session is a real failure.
|
|
142
|
+
if (!authClient.isAuthenticated())
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
succeeded.value = true;
|
|
146
|
+
// Hold the confirmation on screen while the app hook runs; whichever
|
|
147
|
+
// finishes last gates the close.
|
|
148
|
+
const minDisplay = new Promise((resolve) => setTimeout(resolve, SUCCESS_DISPLAY_MS));
|
|
149
|
+
await props.onAuthenticated?.();
|
|
150
|
+
await minDisplay;
|
|
151
|
+
props.onClose?.();
|
|
152
|
+
};
|
|
153
|
+
// OAuth (popup): success/error land back on THIS page; wire them into the
|
|
154
|
+
// composable. A getter keeps the closures current (React re-creates the
|
|
155
|
+
// config object every render).
|
|
156
|
+
const { providers, loginViaPopup } = useOAuth(() => ({
|
|
157
|
+
...props.oauthConfig,
|
|
158
|
+
onSuccess: () => {
|
|
159
|
+
// Surface a finishAuth failure (no session established) in the modal
|
|
160
|
+
// instead of dying as an unhandled rejection.
|
|
161
|
+
finishAuth().catch((error) => {
|
|
162
|
+
oauthError.value = error instanceof Error ? error.message : String(error);
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
onError: (message) => {
|
|
166
|
+
oauthError.value = message;
|
|
167
|
+
},
|
|
168
|
+
}));
|
|
169
|
+
const handleSubmit = async (e) => {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
props.onBeforeAuth?.();
|
|
172
|
+
try {
|
|
173
|
+
if (isSignup.value)
|
|
174
|
+
await signup({
|
|
175
|
+
email: fields.value.email ?? '',
|
|
176
|
+
password: password.value,
|
|
177
|
+
name: name.value || undefined,
|
|
178
|
+
});
|
|
179
|
+
else
|
|
180
|
+
await login({ email: fields.value.email ?? '', password: password.value });
|
|
181
|
+
clear();
|
|
182
|
+
await finishAuth();
|
|
183
|
+
}
|
|
184
|
+
catch (_error) {
|
|
185
|
+
// Auth errors are captured in the composable's error state and shown
|
|
186
|
+
// below; we deliberately do NOT navigate or reload on failure or success.
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Resolves a node-valued prop that may also arrive as a same-named slot.
|
|
191
|
+
* @returns The captcha node(s), or an empty list when neither is present.
|
|
192
|
+
*/
|
|
193
|
+
const captchaNodes = () => {
|
|
194
|
+
if (slots.captchaSlot)
|
|
195
|
+
return slots.captchaSlot();
|
|
196
|
+
return props.captchaSlot != null ? [props.captchaSlot] : [];
|
|
197
|
+
};
|
|
198
|
+
return () => {
|
|
199
|
+
const fieldStyle = {
|
|
200
|
+
width: '100%',
|
|
201
|
+
padding: '10px 12px',
|
|
202
|
+
borderRadius: '6px',
|
|
203
|
+
border: '1px solid var(--mol-color-border, rgba(127,127,127,0.3))',
|
|
204
|
+
background: 'var(--mol-color-surface-secondary, rgba(127,127,127,0.06))',
|
|
205
|
+
color: 'inherit',
|
|
206
|
+
outline: 'none',
|
|
207
|
+
// ≥16px on phones/touch — below 16px iOS Safari zooms the page when an
|
|
208
|
+
// input gains focus, which wrecks the modal on the primary conversion
|
|
209
|
+
// flow. Desktop keeps the compact 14px.
|
|
210
|
+
fontSize: isTouchFirst.value ? '16px' : '14px',
|
|
211
|
+
};
|
|
212
|
+
return h(Modal, {
|
|
213
|
+
open: props.open,
|
|
214
|
+
onClose: () => props.onClose?.(),
|
|
215
|
+
size: 'sm',
|
|
216
|
+
title: isSignup.value
|
|
217
|
+
? t('auth.modal.signupTitle', undefined, { defaultValue: 'Create your account' })
|
|
218
|
+
: t('auth.modal.loginTitle', undefined, { defaultValue: 'Log in' }),
|
|
219
|
+
'data-mol-id': 'auth-modal',
|
|
220
|
+
}, {
|
|
221
|
+
default: () => [
|
|
222
|
+
h('div', {
|
|
223
|
+
'data-mol-id': 'auth-modal-body',
|
|
224
|
+
style: { display: 'flex', flexDirection: 'column' },
|
|
225
|
+
}, succeeded.value
|
|
226
|
+
? [renderSuccess()]
|
|
227
|
+
: [
|
|
228
|
+
h('div', {
|
|
229
|
+
class: cm.textMuted,
|
|
230
|
+
style: { marginBottom: '12px', fontSize: '13px', lineHeight: 1.45 },
|
|
231
|
+
}, isSignup.value
|
|
232
|
+
? t('auth.modal.signupBlurb', undefined, {
|
|
233
|
+
defaultValue: 'Sign up to keep your work.',
|
|
234
|
+
})
|
|
235
|
+
: t('auth.modal.loginBlurb', undefined, {
|
|
236
|
+
defaultValue: 'Log in to keep your work.',
|
|
237
|
+
})),
|
|
238
|
+
h('form', {
|
|
239
|
+
onSubmit: (e) => void handleSubmit(e),
|
|
240
|
+
style: { display: 'grid', gap: '10px' },
|
|
241
|
+
}, renderFormFields(fieldStyle)),
|
|
242
|
+
renderOAuth(),
|
|
243
|
+
h('button', {
|
|
244
|
+
type: 'button',
|
|
245
|
+
'data-mol-id': 'auth-modal-switch',
|
|
246
|
+
onClick: () => {
|
|
247
|
+
mode.value = isSignup.value ? 'login' : 'signup';
|
|
248
|
+
},
|
|
249
|
+
class: cm.cn(cm.button({ variant: 'ghost', size: 'sm' })),
|
|
250
|
+
style: { marginTop: '12px', alignSelf: 'center' },
|
|
251
|
+
}, isSignup.value
|
|
252
|
+
? t('auth.modal.haveAccount', undefined, {
|
|
253
|
+
defaultValue: 'Already have an account? Log in',
|
|
254
|
+
})
|
|
255
|
+
: t('auth.modal.needAccount', undefined, {
|
|
256
|
+
defaultValue: "Don't have an account? Sign up",
|
|
257
|
+
})),
|
|
258
|
+
]),
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Who just authenticated — shown under the headline so the confirmation
|
|
264
|
+
* names the account, not just the outcome.
|
|
265
|
+
* @returns The success confirmation subtree.
|
|
266
|
+
*/
|
|
267
|
+
function renderSuccess() {
|
|
268
|
+
const profile = authClient.getUser();
|
|
269
|
+
const who = profile?.name || profile?.email || profile?.username || '';
|
|
270
|
+
return h('div', {
|
|
271
|
+
'data-mol-id': 'auth-modal-success',
|
|
272
|
+
style: {
|
|
273
|
+
display: 'flex',
|
|
274
|
+
flexDirection: 'column',
|
|
275
|
+
alignItems: 'center',
|
|
276
|
+
gap: '10px',
|
|
277
|
+
padding: '26px 0 18px',
|
|
278
|
+
textAlign: 'center',
|
|
279
|
+
},
|
|
280
|
+
}, [
|
|
281
|
+
h(Icon, { name: 'check-circle', size: 44, class: cm.textSuccess, 'aria-hidden': 'true' }),
|
|
282
|
+
h('div', { style: { fontSize: '17px', fontWeight: 600 } }, isSignup.value
|
|
283
|
+
? t('auth.modal.signedUp', undefined, { defaultValue: 'Signed up!' })
|
|
284
|
+
: t('auth.modal.loggedIn', undefined, { defaultValue: 'Logged in!' })),
|
|
285
|
+
who
|
|
286
|
+
? h('div', { class: cm.textMuted, style: { fontSize: '13px' } }, t('auth.modal.loggedInAs', { who }, { defaultValue: 'Logged in as {{who}}' }))
|
|
287
|
+
: null,
|
|
288
|
+
]);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The form fields for the current mode: name (signup), email, password,
|
|
292
|
+
* two-factor token (login), the captcha challenge (signup only), the
|
|
293
|
+
* submit button and the shown error.
|
|
294
|
+
*
|
|
295
|
+
* @param fieldStyle - The shared input inline style (already sized for the
|
|
296
|
+
* current viewport class).
|
|
297
|
+
* @returns The field vnodes.
|
|
298
|
+
*/
|
|
299
|
+
function renderFormFields(fieldStyle) {
|
|
300
|
+
const nodes = [];
|
|
301
|
+
if (isSignup.value) {
|
|
302
|
+
nodes.push(h('input', {
|
|
303
|
+
key: 'auth-modal-name',
|
|
304
|
+
type: 'text',
|
|
305
|
+
value: name.value,
|
|
306
|
+
onInput: (e) => {
|
|
307
|
+
name.value = e.target.value;
|
|
308
|
+
},
|
|
309
|
+
autocomplete: 'name',
|
|
310
|
+
'data-mol-id': 'auth-modal-name',
|
|
311
|
+
placeholder: t('auth.signup.name', undefined, {
|
|
312
|
+
defaultValue: 'Name (optional)',
|
|
313
|
+
}),
|
|
314
|
+
style: fieldStyle,
|
|
315
|
+
}));
|
|
316
|
+
}
|
|
317
|
+
nodes.push(h('input', {
|
|
318
|
+
key: 'auth-modal-email',
|
|
319
|
+
type: 'email',
|
|
320
|
+
value: fields.value.email ?? '',
|
|
321
|
+
onInput: (e) => {
|
|
322
|
+
setField('email', e.target.value);
|
|
323
|
+
},
|
|
324
|
+
autocomplete: 'email',
|
|
325
|
+
ref: emailRef,
|
|
326
|
+
required: true,
|
|
327
|
+
'data-mol-id': 'auth-modal-email',
|
|
328
|
+
placeholder: t('auth.login.email', undefined, { defaultValue: 'Email' }),
|
|
329
|
+
style: fieldStyle,
|
|
330
|
+
}), h('input', {
|
|
331
|
+
key: 'auth-modal-password',
|
|
332
|
+
type: 'password',
|
|
333
|
+
value: password.value,
|
|
334
|
+
onInput: (e) => {
|
|
335
|
+
password.value = e.target.value;
|
|
336
|
+
},
|
|
337
|
+
autocomplete: isSignup.value ? 'new-password' : 'current-password',
|
|
338
|
+
required: true,
|
|
339
|
+
'data-mol-id': 'auth-modal-password',
|
|
340
|
+
placeholder: t('auth.login.password', undefined, { defaultValue: 'Password' }),
|
|
341
|
+
style: fieldStyle,
|
|
342
|
+
}));
|
|
343
|
+
if (!isSignup.value) {
|
|
344
|
+
nodes.push(h('input', {
|
|
345
|
+
key: 'auth-modal-2fa',
|
|
346
|
+
type: 'text',
|
|
347
|
+
inputmode: 'numeric',
|
|
348
|
+
value: twoFactorToken.value,
|
|
349
|
+
onInput: (e) => {
|
|
350
|
+
twoFactorToken.value = e.target.value;
|
|
351
|
+
},
|
|
352
|
+
autocomplete: 'one-time-code',
|
|
353
|
+
'data-mol-id': 'auth-modal-2fa',
|
|
354
|
+
placeholder: t('auth.login.twoFactor', undefined, {
|
|
355
|
+
defaultValue: 'Two-Factor Token (If enabled)',
|
|
356
|
+
}),
|
|
357
|
+
style: fieldStyle,
|
|
358
|
+
}));
|
|
359
|
+
}
|
|
360
|
+
// Human-verification challenge — signup only (login is not gated).
|
|
361
|
+
const captcha = captchaNodes();
|
|
362
|
+
if (isSignup.value && captcha.length > 0) {
|
|
363
|
+
nodes.push(h('div', { 'data-mol-id': 'auth-modal-captcha', style: { display: 'grid', marginTop: '2px' } }, captcha));
|
|
364
|
+
}
|
|
365
|
+
nodes.push(h(Button, {
|
|
366
|
+
type: 'submit',
|
|
367
|
+
size: 'lg',
|
|
368
|
+
color: 'success',
|
|
369
|
+
disabled: busy.value || (isSignup.value && !props.captchaSolved),
|
|
370
|
+
'data-mol-id': 'auth-modal-submit',
|
|
371
|
+
style: { width: '100%', marginTop: '2px' },
|
|
372
|
+
}, {
|
|
373
|
+
default: () => busy.value
|
|
374
|
+
? t('auth.modal.working', undefined, { defaultValue: 'Just a moment…' })
|
|
375
|
+
: isSignup.value
|
|
376
|
+
? t('auth.login.signUp', undefined, { defaultValue: 'Sign up' })
|
|
377
|
+
: t('auth.login.logIn', undefined, { defaultValue: 'Log in' }),
|
|
378
|
+
}));
|
|
379
|
+
const shownError = errorMessage.value || oauthError.value;
|
|
380
|
+
if (shownError)
|
|
381
|
+
nodes.push(h('div', { class: cm.authFormError }, shownError));
|
|
382
|
+
return nodes;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The popup OAuth section: divider + provider buttons (never navigates the
|
|
386
|
+
* host), rendered only when the OAuth config lists providers.
|
|
387
|
+
* @returns The section vnode, or null without providers.
|
|
388
|
+
*/
|
|
389
|
+
function renderOAuth() {
|
|
390
|
+
const list = providers.value;
|
|
391
|
+
if (list.length === 0)
|
|
392
|
+
return null;
|
|
393
|
+
return h('div', { style: { marginTop: '4px' } }, [
|
|
394
|
+
h(OAuthDivider),
|
|
395
|
+
// Popup OAuth — never navigates the host.
|
|
396
|
+
h(OAuthButtons, {
|
|
397
|
+
providers: list,
|
|
398
|
+
onSelect: (provider) => {
|
|
399
|
+
oauthError.value = null;
|
|
400
|
+
props.onBeforeAuth?.();
|
|
401
|
+
loginViaPopup(provider);
|
|
402
|
+
},
|
|
403
|
+
}),
|
|
404
|
+
]);
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
//# sourceMappingURL=AuthModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthModal.js","sourceRoot":"","sources":["../src/AuthModal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,QAAQ,EACR,eAAe,EACf,CAAC,EACD,QAAQ,EACR,SAAS,EACT,cAAc,EAEd,GAAG,EAGH,KAAK,GACN,MAAM,KAAK,CAAA;AAEZ,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EACL,OAAO,EACP,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,EAER,SAAS,EACT,cAAc,GACf,MAAM,mBAAmB,CAAA;AAI1B;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,uCAAuC,CAAA;AAEjE;;;;;GAKG;AACH,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAS/B;;;;;;GAMG;AACH,SAAS,qBAAqB;IAC5B,MAAM,OAAO,GAAG,GAAG,CACjB,OAAO,MAAM,KAAK,WAAW;QAC3B,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU;QACvC,MAAM,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC,OAAO,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AAC,KAAK,CAAA;YACzD,IAAI,UAAU;gBAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,aAAa,EAAE,EAAE,UAAU,CAAC,CAAC,CAAA;YAC7E,OAAO,KAAK,CAAA;QACd,CAAC;QAED;;;;WAIG;QACH,SAAS,WAAW;YAClB,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAA;YAC5B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,IAAI,CAAA;YAClC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE;gBAC/C,CAAC,CAAC,YAAY,CAAC;gBACf,0CAA0C;gBAC1C,CAAC,CAAC,YAAY,EAAE;oBACd,SAAS,EAAE,IAAI;oBACf,QAAQ,EAAE,CAAC,QAAgB,EAAE,EAAE;wBAC7B,UAAU,CAAC,KAAK,GAAG,IAAI,CAAA;wBACvB,KAAK,CAAC,YAAY,EAAE,EAAE,CAAA;wBACtB,aAAa,CAAC,QAAQ,CAAC,CAAA;oBACzB,CAAC;iBACF,CAAC;aACH,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-mount in-app auth + upgrade flow for any Molecule app.
|
|
3
|
+
*
|
|
4
|
+
* Vue counterpart of `@molecule/app-auth-modal-react`'s `AuthModalMount`: the
|
|
5
|
+
* 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 composables 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 PropType, type VNode } from 'vue';
|
|
23
|
+
import { type AuthModalProps } from './AuthModal.js';
|
|
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 component.
|
|
70
|
+
*/
|
|
71
|
+
export declare const AuthModalMount: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
72
|
+
oauthConfig: null;
|
|
73
|
+
onBeforeAuth: PropType<() => void>;
|
|
74
|
+
onAuthenticated: PropType<() => void | Promise<void>>;
|
|
75
|
+
onUpgradeReturn: PropType<() => void>;
|
|
76
|
+
onUpgradeIntercept: PropType<(path: string) => void>;
|
|
77
|
+
captchaSlot: null;
|
|
78
|
+
captchaSolved: {
|
|
79
|
+
type: BooleanConstructor;
|
|
80
|
+
default: boolean;
|
|
81
|
+
};
|
|
82
|
+
authPaths: {
|
|
83
|
+
type: PropType<Readonly<Record<string, AuthModalMode>>>;
|
|
84
|
+
default: undefined;
|
|
85
|
+
};
|
|
86
|
+
upgradePaths: {
|
|
87
|
+
type: PropType<readonly string[]>;
|
|
88
|
+
default: undefined;
|
|
89
|
+
};
|
|
90
|
+
}>, () => VNode | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
91
|
+
oauthConfig: null;
|
|
92
|
+
onBeforeAuth: PropType<() => void>;
|
|
93
|
+
onAuthenticated: PropType<() => void | Promise<void>>;
|
|
94
|
+
onUpgradeReturn: PropType<() => void>;
|
|
95
|
+
onUpgradeIntercept: PropType<(path: string) => void>;
|
|
96
|
+
captchaSlot: null;
|
|
97
|
+
captchaSolved: {
|
|
98
|
+
type: BooleanConstructor;
|
|
99
|
+
default: boolean;
|
|
100
|
+
};
|
|
101
|
+
authPaths: {
|
|
102
|
+
type: PropType<Readonly<Record<string, AuthModalMode>>>;
|
|
103
|
+
default: undefined;
|
|
104
|
+
};
|
|
105
|
+
upgradePaths: {
|
|
106
|
+
type: PropType<readonly string[]>;
|
|
107
|
+
default: undefined;
|
|
108
|
+
};
|
|
109
|
+
}>> & Readonly<{}>, {
|
|
110
|
+
captchaSolved: boolean;
|
|
111
|
+
authPaths: Readonly<Record<string, AuthModalMode>>;
|
|
112
|
+
upgradePaths: readonly string[];
|
|
113
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
114
|
+
//# sourceMappingURL=AuthModalMount.d.ts.map
|