@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 @@
|
|
|
1
|
+
{"version":3,"file":"AuthModalMount.d.ts","sourceRoot":"","sources":["../src/AuthModalMount.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAA8C,KAAK,QAAQ,EAAO,KAAK,KAAK,EAAE,MAAM,KAAK,CAAA;AAIhG,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/D,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;;;;;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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 { defineComponent, h, onMounted, onUnmounted, ref } from 'vue';
|
|
23
|
+
import { useAuth } from '@molecule/app-vue';
|
|
24
|
+
import { AuthModal } from './AuthModal.js';
|
|
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 component.
|
|
31
|
+
*/
|
|
32
|
+
export const AuthModalMount = defineComponent({
|
|
33
|
+
name: 'AuthModalMount',
|
|
34
|
+
props: {
|
|
35
|
+
oauthConfig: null,
|
|
36
|
+
onBeforeAuth: Function,
|
|
37
|
+
onAuthenticated: Function,
|
|
38
|
+
onUpgradeReturn: Function,
|
|
39
|
+
onUpgradeIntercept: Function,
|
|
40
|
+
captchaSlot: null,
|
|
41
|
+
captchaSolved: { type: Boolean, default: true },
|
|
42
|
+
authPaths: {
|
|
43
|
+
type: Object,
|
|
44
|
+
default: undefined,
|
|
45
|
+
},
|
|
46
|
+
upgradePaths: { type: Array, default: undefined },
|
|
47
|
+
},
|
|
48
|
+
setup(props) {
|
|
49
|
+
const { refresh } = useAuth();
|
|
50
|
+
const open = ref(false);
|
|
51
|
+
const mode = ref('signup');
|
|
52
|
+
const openAuth = (next) => {
|
|
53
|
+
mode.value = next;
|
|
54
|
+
open.value = true;
|
|
55
|
+
};
|
|
56
|
+
// Set when the user opens the upgrade/billing flow in a new tab, so we refresh
|
|
57
|
+
// when they return (a completed upgrade reflects with no manual reload).
|
|
58
|
+
let upgradeTabOpened = false;
|
|
59
|
+
const onFocus = () => {
|
|
60
|
+
if (!upgradeTabOpened)
|
|
61
|
+
return;
|
|
62
|
+
upgradeTabOpened = false;
|
|
63
|
+
refresh().catch((_error) => {
|
|
64
|
+
// Best-effort freshness pass: the user may have returned without a
|
|
65
|
+
// session to refresh (never logged in, or the API has no refresh
|
|
66
|
+
// path) — not an error worth surfacing on a simple tab focus.
|
|
67
|
+
});
|
|
68
|
+
props.onUpgradeReturn?.();
|
|
69
|
+
};
|
|
70
|
+
// Intercept clicks on the in-app /login, /signup (→ modal) and /pricing, /billing
|
|
71
|
+
// (→ host's onUpgradeIntercept, else a new tab) CTAs — plain <a href> links from
|
|
72
|
+
// anywhere in the app, incl. ones opened with target="_blank". Capture-phase +
|
|
73
|
+
// preventDefault stops navigation. Plain left-clicks only — a modifier/middle
|
|
74
|
+
// click still opens the real page.
|
|
75
|
+
const onClick = (e) => {
|
|
76
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)
|
|
77
|
+
return;
|
|
78
|
+
const anchor = e.target?.closest('a[href]');
|
|
79
|
+
if (!anchor)
|
|
80
|
+
return;
|
|
81
|
+
const href = anchor.getAttribute('href');
|
|
82
|
+
const origin = window.location.origin;
|
|
83
|
+
const authMode = authModeForHref(href, origin, props.authPaths ?? DEFAULT_AUTH_PATHS);
|
|
84
|
+
if (authMode) {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
e.stopPropagation();
|
|
87
|
+
openAuth(authMode);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const upgradePath = upgradePathForHref(href, origin, props.upgradePaths ?? DEFAULT_UPGRADE_PATHS);
|
|
91
|
+
if (upgradePath) {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
if (props.onUpgradeIntercept) {
|
|
95
|
+
props.onUpgradeIntercept(upgradePath);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
upgradeTabOpened = true;
|
|
99
|
+
window.open(upgradePath, '_blank', 'noopener,noreferrer');
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
onMounted(() => {
|
|
103
|
+
window.addEventListener('focus', onFocus);
|
|
104
|
+
document.addEventListener('click', onClick, true);
|
|
105
|
+
});
|
|
106
|
+
onUnmounted(() => {
|
|
107
|
+
window.removeEventListener('focus', onFocus);
|
|
108
|
+
document.removeEventListener('click', onClick, true);
|
|
109
|
+
});
|
|
110
|
+
// Mounted only while open so the auth composables don't run on every app render.
|
|
111
|
+
return () => open.value
|
|
112
|
+
? h(AuthModal, {
|
|
113
|
+
open: open.value,
|
|
114
|
+
onClose: () => {
|
|
115
|
+
open.value = false;
|
|
116
|
+
},
|
|
117
|
+
initialMode: mode.value,
|
|
118
|
+
oauthConfig: props.oauthConfig,
|
|
119
|
+
onBeforeAuth: props.onBeforeAuth,
|
|
120
|
+
onAuthenticated: props.onAuthenticated,
|
|
121
|
+
captchaSlot: props.captchaSlot,
|
|
122
|
+
captchaSolved: props.captchaSolved,
|
|
123
|
+
})
|
|
124
|
+
: null;
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=AuthModalMount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthModalMount.js","sourceRoot":"","sources":["../src/AuthModalMount.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAiB,GAAG,EAAc,MAAM,KAAK,CAAA;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE3C,OAAO,EAAE,SAAS,EAAuB,MAAM,gBAAgB,CAAA;AAC/D,OAAO,EAEL,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAA;AA2C3B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;IAC5C,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE;QACL,WAAW,EAAE,IAAI;QACjB,YAAY,EAAE,QAAgC;QAC9C,eAAe,EAAE,QAAgD;QACjE,eAAe,EAAE,QAAgC;QACjD,kBAAkB,EAAE,QAA4C;QAChE,WAAW,EAAE,IAAI;QACjB,aAAa,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;QAC/C,SAAS,EAAE;YACT,IAAI,EAAE,MAA2D;YACjE,OAAO,EAAE,SAAS;SACnB;QACD,YAAY,EAAE,EAAE,IAAI,EAAE,KAAoC,EAAE,OAAO,EAAE,SAAS,EAAE;KACjF;IACD,KAAK,CAAC,KAAK;QACT,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAA;QAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;QACvB,MAAM,IAAI,GAAG,GAAG,CAAgB,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E,IAAI,CAAC,KAAK;gBACvB,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,eAAe,EAAE,KAAK,CAAC,eAAe;gBACtC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;aACnC,CAAC;YACJ,CAAC,CAAC,IAAI,CAAA;IACZ,CAAC;CACF,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,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-modal-vue` — the shared in-app login / signup /
|
|
3
|
+
* upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
|
|
4
|
+
* providers (where the `@molecule/app-vue` auth composables 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
|
+
* ```ts
|
|
13
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
14
|
+
* import { AuthModalMount } from '@molecule/app-auth-modal-vue'
|
|
15
|
+
* import { oauthConfig } from './config.js'
|
|
16
|
+
*
|
|
17
|
+
* // Once, inside the app's providers (e.g. in App.ts):
|
|
18
|
+
* const App = defineComponent({
|
|
19
|
+
* setup() {
|
|
20
|
+
* return () => h(AuthModalMount, { oauthConfig, onAuthenticated: () => claimGuestWork() })
|
|
21
|
+
* },
|
|
22
|
+
* })
|
|
23
|
+
* // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
|
|
24
|
+
* // anywhere in the app is now intercepted — no other wiring needed.
|
|
25
|
+
*
|
|
26
|
+
* createApp(App).mount('#app')
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Interception is capture-phase on `document` and matches plain
|
|
31
|
+
* left-clicks on `<a href>` whose resolved pathname is in `authPaths`
|
|
32
|
+
* (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
|
|
33
|
+
* `/billing`) — modifier/middle clicks still navigate normally, and
|
|
34
|
+
* non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
|
|
35
|
+
* that render pricing in-place pass `onUpgradeIntercept` and own that UI
|
|
36
|
+
* + the post-upgrade session refresh. `AuthModalMount` must render inside
|
|
37
|
+
* the app's auth/HTTP providers (it calls `useAuth`), and the standalone
|
|
38
|
+
* `/login` & `/signup` pages should stay routed — they are the fallback
|
|
39
|
+
* for modifier clicks and deep links. App-specific extras (stash a guest
|
|
40
|
+
* id, claim guest work, invalidate usage) go in `onBeforeAuth` /
|
|
41
|
+
* `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
|
|
42
|
+
* `@molecule/app-locales-common` bond (79 languages), alongside the
|
|
43
|
+
* `auth.login.*` / `auth.signup.*` keys the modal also renders.
|
|
44
|
+
*
|
|
45
|
+
* If the signup API requires a human-verification challenge (Turnstile /
|
|
46
|
+
* hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
|
|
47
|
+
* form — as a prop or a same-named slot) and `captchaSolved` (which gates
|
|
48
|
+
* the submit). Rendering the widget on the standalone `/signup` page alone
|
|
49
|
+
* is NOT enough: this modal is what a `/signup` link actually opens, so the
|
|
50
|
+
* in-app signup would POST with no token and the API would answer "complete
|
|
51
|
+
* the verification challenge" while no challenge is on screen. Login is not
|
|
52
|
+
* gated, so the slot is unmounted in login mode.
|
|
53
|
+
*
|
|
54
|
+
* @module
|
|
55
|
+
*/
|
|
56
|
+
export * from './AuthModal.js';
|
|
57
|
+
export * from './AuthModalMount.js';
|
|
58
|
+
export * from './cta-intercept.js';
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@molecule/app-auth-modal-vue` — the shared in-app login / signup /
|
|
3
|
+
* upgrade flow. Mount {@link AuthModalMount} ONCE inside the app's
|
|
4
|
+
* providers (where the `@molecule/app-vue` auth composables 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
|
+
* ```ts
|
|
13
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
14
|
+
* import { AuthModalMount } from '@molecule/app-auth-modal-vue'
|
|
15
|
+
* import { oauthConfig } from './config.js'
|
|
16
|
+
*
|
|
17
|
+
* // Once, inside the app's providers (e.g. in App.ts):
|
|
18
|
+
* const App = defineComponent({
|
|
19
|
+
* setup() {
|
|
20
|
+
* return () => h(AuthModalMount, { oauthConfig, onAuthenticated: () => claimGuestWork() })
|
|
21
|
+
* },
|
|
22
|
+
* })
|
|
23
|
+
* // Every plain <a href="/login">, <a href="/signup">, <a href="/pricing">
|
|
24
|
+
* // anywhere in the app is now intercepted — no other wiring needed.
|
|
25
|
+
*
|
|
26
|
+
* createApp(App).mount('#app')
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Interception is capture-phase on `document` and matches plain
|
|
31
|
+
* left-clicks on `<a href>` whose resolved pathname is in `authPaths`
|
|
32
|
+
* (default `/login`, `/signup`) or `upgradePaths` (default `/pricing`,
|
|
33
|
+
* `/billing`) — modifier/middle clicks still navigate normally, and
|
|
34
|
+
* non-anchor buttons that call `navigate()` are NOT intercepted. Hosts
|
|
35
|
+
* that render pricing in-place pass `onUpgradeIntercept` and own that UI
|
|
36
|
+
* + the post-upgrade session refresh. `AuthModalMount` must render inside
|
|
37
|
+
* the app's auth/HTTP providers (it calls `useAuth`), and the standalone
|
|
38
|
+
* `/login` & `/signup` pages should stay routed — they are the fallback
|
|
39
|
+
* for modifier clicks and deep links. App-specific extras (stash a guest
|
|
40
|
+
* id, claim guest work, invalidate usage) go in `onBeforeAuth` /
|
|
41
|
+
* `onAuthenticated`. The modal's `auth.modal.*` strings are homed in the
|
|
42
|
+
* `@molecule/app-locales-common` bond (79 languages), alongside the
|
|
43
|
+
* `auth.login.*` / `auth.signup.*` keys the modal also renders.
|
|
44
|
+
*
|
|
45
|
+
* If the signup API requires a human-verification challenge (Turnstile /
|
|
46
|
+
* hCaptcha), pass BOTH `captchaSlot` (the widget, rendered in the signup
|
|
47
|
+
* form — as a prop or a same-named slot) and `captchaSolved` (which gates
|
|
48
|
+
* the submit). Rendering the widget on the standalone `/signup` page alone
|
|
49
|
+
* is NOT enough: this modal is what a `/signup` link actually opens, so the
|
|
50
|
+
* in-app signup would POST with no token and the API would answer "complete
|
|
51
|
+
* the verification challenge" while no challenge is on screen. Login is not
|
|
52
|
+
* gated, so the slot is unmounted in login mode.
|
|
53
|
+
*
|
|
54
|
+
* @module
|
|
55
|
+
*/
|
|
56
|
+
export * from './AuthModal.js';
|
|
57
|
+
export * from './AuthModalMount.js';
|
|
58
|
+
export * from './cta-intercept.js';
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,oBAAoB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-auth-modal-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
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-vue",
|
|
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": "vue-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
|
+
"vue"
|
|
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-vue"
|
|
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-vue": "^1.0.0",
|
|
50
|
+
"@molecule/app-i18n": "^1.0.1",
|
|
51
|
+
"@molecule/app-oauth-buttons-vue": "^1.0.0",
|
|
52
|
+
"@molecule/app-ui": "^1.0.1",
|
|
53
|
+
"@molecule/app-ui-vue": "^1.1.0",
|
|
54
|
+
"@molecule/app-vue": "^3.6.0",
|
|
55
|
+
"vue": "^3.4.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@molecule/app-auth-shell-vue": "1.1.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-vue": "1.2.0",
|
|
63
|
+
"@molecule/app-ui": "1.5.0",
|
|
64
|
+
"@molecule/app-ui-vue": "1.2.1",
|
|
65
|
+
"@molecule/app-vue": "3.9.0",
|
|
66
|
+
"@types/node": "26.6.5",
|
|
67
|
+
"jsdom": "30.1.3",
|
|
68
|
+
"typescript": "6.0.3",
|
|
69
|
+
"vite": "8.3.5",
|
|
70
|
+
"vitest": "4.1.12",
|
|
71
|
+
"vue": "3.5.44",
|
|
72
|
+
"vue-tsc": "3.3.13"
|
|
73
|
+
}
|
|
74
|
+
}
|